Documentation
¶
Index ¶
- Constants
- func ErrorEnvelope(code, message string) ([]byte, error)
- func ErrorFromContractError(ce *ContractError) ([]byte, error)
- func NewError(code, message string) error
- func Render(w io.Writer, envelope []byte, pretty bool) error
- func RequireAtLeastOne(flags map[string]string) error
- func RequireExactlyOne(flags map[string]string) error
- func RequireFlag(name, value string) error
- func Success(data any) ([]byte, error)
- func ValidateFilePath(path string) error
- func ValidateISO8601(value string) error
- func ValidateISO8601Optional(value string) error
- func ValidateURL(value string) error
- type ContractError
Constants ¶
const ( AuthRequired = "AUTH_REQUIRED" AuthInvalid = "AUTH_INVALID" NotFound = "NOT_FOUND" ValidationError = "VALIDATION_ERROR" Conflict = "CONFLICT" RateLimited = "RATE_LIMITED" HTTPError = "HTTP_ERROR" FileNotFound = "FILE_NOT_FOUND" Unsupported = "UNSUPPORTED" UnknownError = "UNKNOWN_ERROR" )
Variables ¶
This section is empty.
Functions ¶
func ErrorEnvelope ¶
ErrorEnvelope builds a JSON error envelope from a code and message.
func ErrorFromContractError ¶
func ErrorFromContractError(ce *ContractError) ([]byte, error)
ErrorFromContractError builds a JSON error envelope from a ContractError.
func RequireAtLeastOne ¶
RequireAtLeastOne returns a VALIDATION_ERROR if no flags have a non-empty value.
func RequireExactlyOne ¶
RequireExactlyOne returns a VALIDATION_ERROR if not exactly one flag has a non-empty value.
func RequireFlag ¶
RequireFlag returns a VALIDATION_ERROR if value is empty.
func ValidateFilePath ¶
ValidateFilePath returns a FILE_NOT_FOUND if the path is empty or does not exist.
func ValidateISO8601 ¶
ValidateISO8601 returns a VALIDATION_ERROR if the value is not a valid ISO-8601 date.
func ValidateISO8601Optional ¶
ValidateISO8601Optional validates an ISO-8601 date only if non-empty.
func ValidateURL ¶
ValidateURL returns a VALIDATION_ERROR if the value is not a valid HTTP(S) URL.
Types ¶
type ContractError ¶
ContractError represents a structured CLI error with a machine-readable code.
func (*ContractError) Error ¶
func (e *ContractError) Error() string