package jobs import "errors" // Error codes persisted with terminal failures (P6 DLQ). The table is closed: // a handler without an explicit code lands in "handler_error" so the DLQ never // shows a blank classification. const ( ErrCodeNoHandler = "no_handler" ErrCodeArtifactInvalid = "artifact_invalid" ErrCodeRemotePermanent = "remote_permanent" ErrCodeUploadIdentity = "upload_identity_ambiguous" ErrCodeValidationFailed = "validation_failed" ErrCodeStateConflict = "state_conflict" ErrCodeHandlerFallback = "handler_error" ) // PermanentError marks a failure that must not consume the retry budget: // the job goes straight to the terminal (dead-letter) state. type PermanentError struct { Code string Err error } func (e *PermanentError) Error() string { return e.Err.Error() } func (e *PermanentError) Unwrap() error { return e.Err } func Permanent(code string, err error) error { return &PermanentError{Code: safeCode(code), Err: err} } // Terminal reports whether an error must fail immediately plus its stable code. func Terminal(err error) (bool, string) { var permanent *PermanentError if errors.As(err, &permanent) { return true, safeCode(permanent.Code) } return false, ErrCodeHandlerFallback } func safeCode(code string) string { if code == "" || len(code) > 64 { return ErrCodeHandlerFallback } for _, r := range code { if !(r == '_' || r >= 'a' && r <= 'z' || r >= '0' && r <= '9') { return ErrCodeHandlerFallback } } return code }