MCPcopy Create free account
hub / github.com/compozy/agh / ExitCodeForError

Function ExitCodeForError

internal/agentidentity/errors.go:166–208  ·  view source on GitHub ↗

ExitCodeForError maps agent identity and command errors to deterministic CLI exit codes.

(err error)

Source from the content-addressed store, hash-verified

164
165// ExitCodeForError maps agent identity and command errors to deterministic CLI exit codes.
166func ExitCodeForError(err error) int {
167 switch {
168 case err == nil:
169 return ExitOK
170 case errors.Is(err, ErrIdentityRequired):
171 return ExitIdentityRequired
172 case errors.Is(err, ErrIdentityLookupUnavailable):
173 return ExitUnavailable
174 case errors.Is(err, ErrIdentityMismatch), errors.Is(err, ErrIdentityStale):
175 return ExitIdentityInvalid
176 case errors.Is(err, ErrIdentityUnauthorized):
177 return ExitUnauthorized
178 default:
179 diagnosticErr, ok := errors.AsType[interface {
180 error
181 DiagnosticItem() contract.DiagnosticItem
182 }](err)
183 if ok {
184 item := diagnosticErr.DiagnosticItem()
185 switch item.Code {
186 case contract.CodeConfigInvalid:
187 return ExitConfigInvalid
188 case contract.CodeDaemonUnavailable:
189 return ExitUnavailable
190 case contract.CodeIdentityRequired:
191 return ExitIdentityRequired
192 case contract.CodeIdentityStale, contract.CodeIdentityMismatch:
193 return ExitIdentityInvalid
194 case contract.CodeIdentityUnauthorized:
195 return ExitUnauthorized
196 case contract.CodeIdentityLookupUnavailable:
197 return ExitUnavailable
198 }
199 switch item.Severity {
200 case contract.SeverityWarn:
201 return ExitDoctorWarn
202 case contract.SeverityError, contract.SeverityCritical:
203 return ExitDoctorError
204 }
205 }
206 return ExitUnavailable
207 }
208}
209
210func identityError(err error, code string, message string, action string) error {
211 return &Error{

Calls 2

DiagnosticItemMethod · 0.65
IsMethod · 0.45