ExitCodeForCategory maps an errs.Category to the shell exit code. Multiple categories may share an exit code (Authentication / Authorization / Config all map to 3), so the relationship is many-to-one.
(cat errs.Category)
| 27 | // Multiple categories may share an exit code (Authentication / Authorization / |
| 28 | // Config all map to 3), so the relationship is many-to-one. |
| 29 | func ExitCodeForCategory(cat errs.Category) int { |
| 30 | switch cat { |
| 31 | case errs.CategoryValidation: |
| 32 | return ExitValidation |
| 33 | case errs.CategoryAuthentication, errs.CategoryAuthorization, errs.CategoryConfig: |
| 34 | return ExitAuth |
| 35 | case errs.CategoryNetwork: |
| 36 | return ExitNetwork |
| 37 | case errs.CategoryAPI: |
| 38 | return ExitAPI |
| 39 | case errs.CategoryPolicy: |
| 40 | return ExitContentSafety |
| 41 | case errs.CategoryInternal: |
| 42 | return ExitInternal |
| 43 | case errs.CategoryConfirmation: |
| 44 | return ExitConfirmationRequired |
| 45 | } |
| 46 | return ExitInternal |
| 47 | } |
| 48 | |
| 49 | // ExitCodeOf returns the shell exit code for any error. |
| 50 | // - typed errors (*errs.PermissionError, *errs.APIError, *errs.ConfigError, |
no outgoing calls