diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-04 08:13:13 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-04 08:13:13 +0200 |
| commit | 38673b29da62195f3056599394ab258c50c2e124 (patch) | |
| tree | 1682000cbb5cae6f7b95910cb56f5800fc6fe800 | |
| parent | fb8e134c6c7093eb4fee84d0d667f2c41cd47f89 (diff) | |
timer: add timeout to task tracking command
| -rw-r--r-- | internal/timer/operations.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/internal/timer/operations.go b/internal/timer/operations.go index 993ad12..0653140 100644 --- a/internal/timer/operations.go +++ b/internal/timer/operations.go @@ -1,6 +1,7 @@ package timer import ( + "context" "errors" "fmt" "os" @@ -13,14 +14,22 @@ type Tracker interface { Track(description string, minutes int) error } +const trackCommandTimeout = 10 * time.Second + type taskwarriorTracker struct{} func (taskwarriorTracker) Track(description string, minutes int) error { taskDescription := fmt.Sprintf("%dmin %s", minutes, description) - cmd := exec.Command("task", "add", "+track", taskDescription) + ctx, cancel := context.WithTimeout(context.Background(), trackCommandTimeout) + defer cancel() + + cmd := exec.CommandContext(ctx, "task", "add", "+track", taskDescription) output, err := cmd.CombinedOutput() if err != nil { + if errors.Is(ctx.Err(), context.DeadlineExceeded) { + return fmt.Errorf("task command timed out after %s", trackCommandTimeout) + } return fmt.Errorf("task command failed: %s\nOutput: %s", err, string(output)) } |
