| 352 | } |
| 353 | |
| 354 | func exitCodeForError(err error) int { |
| 355 | if err == nil { |
| 356 | return exitCodeSuccess |
| 357 | } |
| 358 | |
| 359 | switch jsonErrorCode(err) { |
| 360 | case jsonErrorCodeAppKeyRequired, |
| 361 | jsonErrorCodeAuthExchangeFailed, |
| 362 | jsonErrorCodeAuthRefreshFailed, |
| 363 | jsonErrorCodeAuthRequired, |
| 364 | jsonErrorCodeEnvTokenStillActive: |
| 365 | return exitCodeAuthFailure |
| 366 | case jsonErrorCodePermissionDenied: |
| 367 | return exitCodePermissionDenied |
| 368 | case jsonErrorCodeNotFound: |
| 369 | return exitCodeNotFound |
| 370 | case jsonErrorCodePathConflict: |
| 371 | return exitCodeConflict |
| 372 | case jsonErrorCodeRateLimited: |
| 373 | return exitCodeRateLimited |
| 374 | case jsonErrorCodeInvalidArguments, |
| 375 | jsonErrorCodeStructuredOutputUnsupported, |
| 376 | jsonErrorCodeUnknownCommand, |
| 377 | jsonErrorCodeUnknownFlag: |
| 378 | return exitCodeValidationError |
| 379 | case jsonErrorCodePartialTransfer: |
| 380 | return exitCodePartialTransfer |
| 381 | default: |
| 382 | return exitCodeGenericError |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // outputJSONRequested is a narrow pre-parse fallback for errors that happen |
| 387 | // before Cobra has resolved a command/flag context, such as unknown commands. |