diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 10:32:36 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 10:32:36 +0300 |
| commit | 75fd7c03b1a8018f85e2da779ab59b86ad0efb58 (patch) | |
| tree | a3b155ad9abb66a820d31e839aa023c1d45c3516 /internal | |
| parent | 6d407096405520d5e157235e52773b9a4f3e4396 (diff) | |
fix: move context.Context to first parameter in startTraceCmd and startTraceCmdWithTimeout
Per Go convention, context.Context must always be the first parameter. Updated
both function signatures and all call sites in tracelifecycle.go and tui_test.go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/tui/tracelifecycle.go | 10 | ||||
| -rw-r--r-- | internal/tui/tui_test.go | 8 |
2 files changed, 10 insertions, 8 deletions
diff --git a/internal/tui/tracelifecycle.go b/internal/tui/tracelifecycle.go index 0117169..99b1c86 100644 --- a/internal/tui/tracelifecycle.go +++ b/internal/tui/tracelifecycle.go @@ -39,7 +39,7 @@ func (t *traceLifecycle) beginCmd(runtime *runtimeBindings, filter globalfilter. t.traceStop = cancel ctx = ContextWithRuntimeBindings(ctx, runtime) ctx = ContextWithTraceFilters(ctx, filter) - return startTraceCmd(t.startTrace, ctx) + return startTraceCmd(ctx, t.startTrace) } // stop cancels the running trace and clears the cancel function. Safe to call @@ -63,14 +63,16 @@ const defaultStartupTimeout = 30 * time.Second // cancellation gracefully (returns nil so the caller does not treat a // user-initiated stop as an error). It uses defaultStartupTimeout to // prevent the TUI from hanging indefinitely when BPF probe attachment stalls. -func startTraceCmd(starter TraceStarter, ctx context.Context) tea.Cmd { - return startTraceCmdWithTimeout(starter, ctx, defaultStartupTimeout) +// ctx is first per Go convention (context.Context always leads the parameter list). +func startTraceCmd(ctx context.Context, starter TraceStarter) tea.Cmd { + return startTraceCmdWithTimeout(ctx, starter, defaultStartupTimeout) } // startTraceCmdWithTimeout is the testable core of startTraceCmd. It races // the starter goroutine against a caller-supplied timeout so that tests can // use a short deadline without waiting 30 seconds. -func startTraceCmdWithTimeout(starter TraceStarter, ctx context.Context, timeout time.Duration) tea.Cmd { +// ctx is first per Go convention (context.Context always leads the parameter list). +func startTraceCmdWithTimeout(ctx context.Context, starter TraceStarter, timeout time.Duration) tea.Cmd { return func() tea.Msg { type starterResult struct{ err error } ch := make(chan starterResult, 1) diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index a685719..5f007e4 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -202,7 +202,7 @@ func TestQuitKeyMatchesSingleBindingWithoutPanic(t *testing.T) { } func TestStartTraceCmdLaunchesBeforeStarterReturns(t *testing.T) { - cmd := startTraceCmd(func(context.Context) error { return nil }, context.Background()) + cmd := startTraceCmd(context.Background(), func(context.Context) error { return nil }) msg := cmd() if _, ok := msg.(TracingStartedMsg); !ok { t.Fatalf("expected TracingStartedMsg, got %T", msg) @@ -210,7 +210,7 @@ func TestStartTraceCmdLaunchesBeforeStarterReturns(t *testing.T) { } func TestStartTraceCmdEmitsErrorMsg(t *testing.T) { - cmd := startTraceCmd(func(context.Context) error { return errors.New("trace failed") }, context.Background()) + cmd := startTraceCmd(context.Background(), func(context.Context) error { return errors.New("trace failed") }) msg := cmd() traceErr, ok := msg.(TracingErrorMsg) if !ok { @@ -235,7 +235,7 @@ func TestStartTraceCmdTimeoutEmitsErrorMsg(t *testing.T) { } // Use a short timeout so the test finishes quickly. - cmd := startTraceCmdWithTimeout(blocker, ctx, 50*time.Millisecond) + cmd := startTraceCmdWithTimeout(ctx, blocker, 50*time.Millisecond) msg := cmd() traceErr, ok := msg.(TracingErrorMsg) @@ -265,7 +265,7 @@ func TestStartTraceCmdContextCancelledBeforeTimeoutReturnsNil(t *testing.T) { // Cancel ctx immediately so the starter exits before the timeout. cancel() - cmd := startTraceCmdWithTimeout(blocker, ctx, 5*time.Second) + cmd := startTraceCmdWithTimeout(ctx, blocker, 5*time.Second) msg := cmd() if msg != nil { |
