Skip to content

Commit 12e2f90

Browse files
committed
Track command errors with success=false and error details
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
1 parent 47cb9f8 commit 12e2f90

15 files changed

Lines changed: 112 additions & 31 deletions

File tree

cmd/root/a2a.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ func newA2ACmd() *cobra.Command {
3535
return cmd
3636
}
3737

38-
func (f *a2aFlags) runA2ACommand(cmd *cobra.Command, args []string) error {
38+
func (f *a2aFlags) runA2ACommand(cmd *cobra.Command, args []string) (commandErr error) {
3939
ctx := cmd.Context()
4040
telemetry.TrackCommand(ctx, "serve", append([]string{"a2a"}, args...))
41+
defer func() { // do not inline this defer so that commandErr is not resolved early
42+
telemetry.TrackCommandError(ctx, "serve", append([]string{"a2a"}, args...), commandErr)
43+
}()
4144

4245
out := cli.NewPrinter(cmd.OutOrStdout())
4346
agentFilename := args[0]

cmd/root/acp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ func newACPCmd() *cobra.Command {
3636
return cmd
3737
}
3838

39-
func (f *acpFlags) runACPCommand(cmd *cobra.Command, args []string) error {
39+
func (f *acpFlags) runACPCommand(cmd *cobra.Command, args []string) (commandErr error) {
4040
ctx := cmd.Context()
4141
telemetry.TrackCommand(ctx, "serve", append([]string{"acp"}, args...))
42+
defer func() { // do not inline this defer so that commandErr is not resolved early
43+
telemetry.TrackCommandError(ctx, "serve", append([]string{"acp"}, args...), commandErr)
44+
}()
4245

4346
agentFilename := args[0]
4447

cmd/root/alias.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ func newAliasRemoveCmd() *cobra.Command {
111111
}
112112
}
113113

114-
func runAliasAddCommand(cmd *cobra.Command, args []string, flags *aliasAddFlags) error {
114+
func runAliasAddCommand(cmd *cobra.Command, args []string, flags *aliasAddFlags) (commandErr error) {
115115
telemetry.TrackCommand(cmd.Context(), "alias", append([]string{"add"}, args...))
116+
defer func() { // do not inline this defer so that commandErr is not resolved early
117+
telemetry.TrackCommandError(cmd.Context(), "alias", append([]string{"add"}, args...), commandErr)
118+
}()
116119

117120
out := cli.NewPrinter(cmd.OutOrStdout())
118121
name := args[0]
@@ -178,8 +181,11 @@ func runAliasAddCommand(cmd *cobra.Command, args []string, flags *aliasAddFlags)
178181
return nil
179182
}
180183

181-
func runAliasListCommand(cmd *cobra.Command, args []string) error {
184+
func runAliasListCommand(cmd *cobra.Command, args []string) (commandErr error) {
182185
telemetry.TrackCommand(cmd.Context(), "alias", append([]string{"list"}, args...))
186+
defer func() { // do not inline this defer so that commandErr is not resolved early
187+
telemetry.TrackCommandError(cmd.Context(), "alias", append([]string{"list"}, args...), commandErr)
188+
}()
183189

184190
out := cli.NewPrinter(cmd.OutOrStdout())
185191

@@ -234,8 +240,11 @@ func runAliasListCommand(cmd *cobra.Command, args []string) error {
234240
return nil
235241
}
236242

237-
func runAliasRemoveCommand(cmd *cobra.Command, args []string) error {
243+
func runAliasRemoveCommand(cmd *cobra.Command, args []string) (commandErr error) {
238244
telemetry.TrackCommand(cmd.Context(), "alias", append([]string{"remove"}, args...))
245+
defer func() {
246+
telemetry.TrackCommandError(cmd.Context(), "alias", append([]string{"remove"}, args...), commandErr)
247+
}()
239248

240249
out := cli.NewPrinter(cmd.OutOrStdout())
241250
name := args[0]

cmd/root/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ func newAPICmd() *cobra.Command {
4646
return cmd
4747
}
4848

49-
func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
49+
func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) (commandErr error) {
5050
ctx := cmd.Context()
5151
telemetry.TrackCommand(ctx, "serve", append([]string{"api"}, args...))
52+
defer func() { // do not inline this defer so that commandErr is not resolved early
53+
telemetry.TrackCommandError(ctx, "serve", append([]string{"api"}, args...), commandErr)
54+
}()
5255

5356
out := cli.NewPrinter(cmd.OutOrStdout())
5457
agentsPath := args[0]

cmd/root/debug.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ func (f *debugFlags) loadTeam(ctx context.Context, agentFilename string, opts ..
7575
return t, nil
7676
}
7777

78-
func (f *debugFlags) runDebugConfigCommand(cmd *cobra.Command, args []string) error {
78+
func (f *debugFlags) runDebugConfigCommand(cmd *cobra.Command, args []string) (commandErr error) {
7979
telemetry.TrackCommand(cmd.Context(), "debug", append([]string{"config"}, args...))
80+
defer func() { // do not inline this defer so that commandErr is not resolved early
81+
telemetry.TrackCommandError(cmd.Context(), "debug", append([]string{"config"}, args...), commandErr)
82+
}()
8083

8184
agentSource, err := config.Resolve(args[0], f.runConfig.EnvProvider())
8285
if err != nil {
@@ -91,8 +94,11 @@ func (f *debugFlags) runDebugConfigCommand(cmd *cobra.Command, args []string) er
9194
return yaml.NewEncoder(cmd.OutOrStdout()).Encode(cfg)
9295
}
9396

94-
func (f *debugFlags) runDebugToolsetsCommand(cmd *cobra.Command, args []string) error {
97+
func (f *debugFlags) runDebugToolsetsCommand(cmd *cobra.Command, args []string) (commandErr error) {
9598
telemetry.TrackCommand(cmd.Context(), "debug", append([]string{"toolsets"}, args...))
99+
defer func() { // do not inline this defer so that commandErr is not resolved early
100+
telemetry.TrackCommandError(cmd.Context(), "debug", append([]string{"toolsets"}, args...), commandErr)
101+
}()
96102

97103
ctx := cmd.Context()
98104

@@ -131,8 +137,11 @@ func (f *debugFlags) runDebugToolsetsCommand(cmd *cobra.Command, args []string)
131137
return nil
132138
}
133139

134-
func (f *debugFlags) runDebugTitleCommand(cmd *cobra.Command, args []string) error {
140+
func (f *debugFlags) runDebugTitleCommand(cmd *cobra.Command, args []string) (commandErr error) {
135141
telemetry.TrackCommand(cmd.Context(), "debug", append([]string{"title"}, args...))
142+
defer func() { // do not inline this defer so that commandErr is not resolved early
143+
telemetry.TrackCommandError(cmd.Context(), "debug", append([]string{"title"}, args...), commandErr)
144+
}()
136145

137146
ctx := cmd.Context()
138147

cmd/root/debug_auth.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ func newDebugAuthCmd() *cobra.Command {
3232
Use: "auth",
3333
Short: "Print Docker Desktop authentication information",
3434
Args: cobra.NoArgs,
35-
RunE: func(cmd *cobra.Command, _ []string) error {
35+
RunE: func(cmd *cobra.Command, _ []string) (commandErr error) {
3636
ctx := cmd.Context()
3737
telemetry.TrackCommand(ctx, "debug", []string{"auth"})
38+
defer func() { // do not inline this defer so that commandErr is not resolved early
39+
telemetry.TrackCommandError(ctx, "debug", []string{"auth"}, commandErr)
40+
}()
3841

3942
w := cmd.OutOrStdout()
4043

cmd/root/eval.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ func newEvalCmd() *cobra.Command {
4949
return cmd
5050
}
5151

52-
func (f *evalFlags) runEvalCommand(cmd *cobra.Command, args []string) error {
52+
func (f *evalFlags) runEvalCommand(cmd *cobra.Command, args []string) (commandErr error) {
5353
telemetry.TrackCommand(cmd.Context(), "eval", args)
54+
defer func() { // do not inline this defer so that commandErr is not resolved early
55+
telemetry.TrackCommandError(cmd.Context(), "eval", args, commandErr)
56+
}()
5457

5558
ctx := cmd.Context()
5659
agentFilename := args[0]

cmd/root/mcp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ func newMCPCmd() *cobra.Command {
3838
return cmd
3939
}
4040

41-
func (f *mcpFlags) runMCPCommand(cmd *cobra.Command, args []string) error {
41+
func (f *mcpFlags) runMCPCommand(cmd *cobra.Command, args []string) (commandErr error) {
4242
ctx := cmd.Context()
4343
telemetry.TrackCommand(ctx, "serve", append([]string{"mcp"}, args...))
44+
defer func() { // do not inline this defer so that commandErr is not resolved early
45+
telemetry.TrackCommandError(ctx, "serve", append([]string{"mcp"}, args...), commandErr)
46+
}()
4447

4548
agentFilename := args[0]
4649

cmd/root/new.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ Optionally provide a description as an argument to skip the initial prompt.`,
5050
return cmd
5151
}
5252

53-
func (f *newFlags) runNewCommand(cmd *cobra.Command, args []string) error {
53+
func (f *newFlags) runNewCommand(cmd *cobra.Command, args []string) (commandErr error) {
5454
ctx := cmd.Context()
5555
telemetry.TrackCommand(ctx, "new", args)
56+
defer func() { // do not inline this defer so that commandErr is not resolved early
57+
telemetry.TrackCommandError(ctx, "new", args, commandErr)
58+
}()
5659

5760
t, err := creator.Agent(ctx, &f.runConfig, f.modelParam)
5861
if err != nil {

cmd/root/pull.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ func newPullCmd() *cobra.Command {
3434
return cmd
3535
}
3636

37-
func (f *pullFlags) runPullCommand(cmd *cobra.Command, args []string) error {
37+
func (f *pullFlags) runPullCommand(cmd *cobra.Command, args []string) (commandErr error) {
3838
ctx := cmd.Context()
3939
telemetry.TrackCommand(ctx, "share", append([]string{"pull"}, args...))
40+
defer func() { // do not inline this defer so that commandErr is not resolved early
41+
telemetry.TrackCommandError(ctx, "share", append([]string{"pull"}, args...), commandErr)
42+
}()
4043

4144
out := cli.NewPrinter(cmd.OutOrStdout())
4245
registryRef := args[0]

0 commit comments

Comments
 (0)