package promptkit import ( "fmt" "strings" ) // CapacityError reports bounded admission rejected for a selected backend. // // Engine-produced values identify only rejection at Promptkit's bounded // [Engine.Run] or [Engine.RunPrepared] admission boundary. BackendID is the // normalized registered backend ID used for routing and capacity; endpoint // overrides do not change it. Every engine-produced value is nonnil and has a // nonblank BackendID. Provider errors, active-generation waiting, and caller // cancellation are not represented by this type. // // Callers own returned values and may mutate BackendID without affecting engine // state or another error. CapacityError and its default Go encoding have no // stable JSON contract. Consumer-constructed values do not establish that an // engine rejected work. type CapacityError struct { // BackendID is the normalized registered backend ID whose admission was // rejected. BackendID string } // Error returns diagnostic wording that is not a parsing contract. It is safe // to call on a nil receiver or a value with a blank BackendID. func (e *CapacityError) Error() string { if e == nil || strings.TrimSpace(e.BackendID) == "" { return ErrCapacityExceeded.Error() } return fmt.Sprintf("backend %q admission: %v", e.BackendID, ErrCapacityExceeded) } // Unwrap returns ErrCapacityExceeded so errors.Is and errors.As can be used // together. It is safe to call on a nil receiver or a zero value. func (e *CapacityError) Unwrap() error { return ErrCapacityExceeded }