| 184 | } |
| 185 | |
| 186 | func writeExecutionError(stderr io.Writer, args []string, err error) int { |
| 187 | exitCode := cliExitCodeForError(err) |
| 188 | if payload, ok := marshalStructuredExecutionError(args, err); ok { |
| 189 | if _, writeErr := stderr.Write(payload); writeErr == nil { |
| 190 | if len(payload) == 0 || payload[len(payload)-1] != '\n' { |
| 191 | _, _ = fmt.Fprintln(stderr) |
| 192 | } |
| 193 | return exitCode |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | _, _ = fmt.Fprintf(stderr, "error: %v\n", err) |
| 198 | return exitCode |
| 199 | } |
| 200 | |
| 201 | func marshalStructuredExecutionError(args []string, err error) ([]byte, bool) { |
| 202 | if !isStructuredAgentCommandError(err) { |