From 38673b29da62195f3056599394ab258c50c2e124 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 4 Mar 2026 08:13:13 +0200 Subject: timer: add timeout to task tracking command --- internal/timer/operations.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'internal/timer') 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)) } -- cgit v1.2.3