errors

package
v3.1.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// Machine-readable error code (e.g., "REPO_NOT_FOUND")
	Code string `json:"code"`

	// Human-readable error message
	Message string `json:"message"`

	// HTTP status code
	Status int `json:"status"`

	// Additional context about the error
	Details map[string]any `json:"details,omitempty"`

	// URL to documentation about this error
	DocumentationURL string `json:"documentation_url,omitempty"`

	// Unique request ID for tracing
	RequestID string `json:"request_id,omitempty"`

	// Suggested actions or alternatives
	Suggestions []string `json:"suggestions,omitempty"`

	// RFC 7807 Problem Details fields
	Type     string `json:"type,omitempty"`     // URI reference identifying the problem type
	Title    string `json:"title,omitempty"`    // Short summary of the problem type
	Instance string `json:"instance,omitempty"` // URI reference for this specific occurrence
}

APIError represents a structured API error following RFC 7807 Problem Details with additional fields for AI-friendly error handling

func NewAPIError

func NewAPIError(code ErrorCode, requestID string) *APIError

NewAPIError creates a new structured API error

func (*APIError) Response

func (e *APIError) Response() *APIErrorResponse

Response wraps the error in an APIErrorResponse

func (*APIError) WithDetail

func (e *APIError) WithDetail(key string, value any) *APIError

WithDetail adds a single detail to the error

func (*APIError) WithDetails

func (e *APIError) WithDetails(details map[string]any) *APIError

WithDetails adds details to the error

func (*APIError) WithMessage

func (e *APIError) WithMessage(message string) *APIError

WithMessage overrides the default message

func (*APIError) WithSuggestions

func (e *APIError) WithSuggestions(suggestions ...string) *APIError

WithSuggestions adds suggested actions

type APIErrorResponse

type APIErrorResponse struct {
	Error *APIError `json:"error"`
}

APIErrorResponse is the top-level error response wrapper

type APIValidationError

type APIValidationError struct {
	*APIError
	Errors []ValidationError `json:"errors,omitempty"`
}

APIValidationError represents a validation error with field-level details

func NewValidationError

func NewValidationError(requestID string, errors ...ValidationError) *APIValidationError

NewValidationError creates a new validation error

func (*APIValidationError) AddFieldError

func (e *APIValidationError) AddFieldError(field, message string, code ...string) *APIValidationError

AddFieldError adds a field validation error

type ErrorCode

type ErrorCode string

ErrorCode represents a machine-readable error code

const (
	AuthTokenMissing       ErrorCode = "AUTH_TOKEN_MISSING"
	AuthTokenInvalid       ErrorCode = "AUTH_TOKEN_INVALID"
	AuthTokenExpired       ErrorCode = "AUTH_TOKEN_EXPIRED"
	AuthScopeInsufficient  ErrorCode = "AUTH_SCOPE_INSUFFICIENT"
	Auth2FARequired        ErrorCode = "AUTH_2FA_REQUIRED"
	AuthInvalidCredentials ErrorCode = "AUTH_INVALID_CREDENTIALS"
)

Authentication errors (AUTH_)

const (
	PermRepoReadDenied    ErrorCode = "PERM_REPO_READ_DENIED"
	PermRepoWriteDenied   ErrorCode = "PERM_REPO_WRITE_DENIED"
	PermRepoAdminRequired ErrorCode = "PERM_REPO_ADMIN_REQUIRED"
	PermOrgMemberRequired ErrorCode = "PERM_ORG_MEMBER_REQUIRED"
	PermOrgAdminRequired  ErrorCode = "PERM_ORG_ADMIN_REQUIRED"
	PermActionDenied      ErrorCode = "PERM_ACTION_DENIED"
)

Permission errors (PERM_)

const (
	RepoNotFound        ErrorCode = "REPO_NOT_FOUND"
	RepoArchived        ErrorCode = "REPO_ARCHIVED"
	RepoDisabled        ErrorCode = "REPO_DISABLED"
	RepoTransferPending ErrorCode = "REPO_TRANSFER_PENDING"
	RepoEmpty           ErrorCode = "REPO_EMPTY"
	RepoAlreadyExists   ErrorCode = "REPO_ALREADY_EXISTS"
)

Repository errors (REPO_)

const (
	FileNotFound  ErrorCode = "FILE_NOT_FOUND"
	FileTooLarge  ErrorCode = "FILE_TOO_LARGE"
	FileConflict  ErrorCode = "FILE_CONFLICT"
	FileBinary    ErrorCode = "FILE_BINARY"
	FileTypeError ErrorCode = "FILE_TYPE_NOT_ALLOWED"
)

File errors (FILE_)

const (
	GitRefNotFound    ErrorCode = "GIT_REF_NOT_FOUND"
	GitMergeConflict  ErrorCode = "GIT_MERGE_CONFLICT"
	GitBranchNotFound ErrorCode = "GIT_BRANCH_NOT_FOUND"
	GitTagNotFound    ErrorCode = "GIT_TAG_NOT_FOUND"
	GitCommitNotFound ErrorCode = "GIT_COMMIT_NOT_FOUND"
	GitPushRejected   ErrorCode = "GIT_PUSH_REJECTED"
)

Git errors (GIT_)

const (
	RateLimitExceeded  ErrorCode = "RATE_LIMIT_EXCEEDED"
	RateQuotaExhausted ErrorCode = "RATE_QUOTA_EXHAUSTED"
)

Rate limiting errors (RATE_)

const (
	ValInvalidInput  ErrorCode = "VAL_INVALID_INPUT"
	ValMissingField  ErrorCode = "VAL_MISSING_FIELD"
	ValInvalidName   ErrorCode = "VAL_INVALID_NAME"
	ValNameTooLong   ErrorCode = "VAL_NAME_TOO_LONG"
	ValInvalidEmail  ErrorCode = "VAL_INVALID_EMAIL"
	ValDuplicateName ErrorCode = "VAL_DUPLICATE_NAME"
	ValInvalidFormat ErrorCode = "VAL_INVALID_FORMAT"
	ValidationFailed ErrorCode = "VALIDATION_FAILED"
)

Validation errors (VAL_)

const (
	InternalError    ErrorCode = "INTERNAL_ERROR"
	PermAccessDenied ErrorCode = "ACCESS_DENIED"
	RefNotFound      ErrorCode = "REF_NOT_FOUND"
)

General errors

const (
	UploadSessionNotFound   ErrorCode = "UPLOAD_SESSION_NOT_FOUND"
	UploadSessionExpired    ErrorCode = "UPLOAD_SESSION_EXPIRED"
	UploadChunkInvalid      ErrorCode = "UPLOAD_CHUNK_INVALID"
	UploadChunkSizeMismatch ErrorCode = "UPLOAD_CHUNK_SIZE_MISMATCH"
	UploadChecksumMismatch  ErrorCode = "UPLOAD_CHECKSUM_MISMATCH"
	UploadIncomplete        ErrorCode = "UPLOAD_INCOMPLETE"
	UploadFileTooLarge      ErrorCode = "UPLOAD_FILE_TOO_LARGE"
)

Upload errors (UPLOAD_)

const (
	ResourceNotFound ErrorCode = "RESOURCE_NOT_FOUND"
	ResourceConflict ErrorCode = "RESOURCE_CONFLICT"
	ResourceGone     ErrorCode = "RESOURCE_GONE"
)

Resource errors (RESOURCE_)

const (
	ServerInternal    ErrorCode = "SERVER_INTERNAL_ERROR"
	ServerUnavailable ErrorCode = "SERVER_UNAVAILABLE"
	ServerTimeout     ErrorCode = "SERVER_TIMEOUT"
)

Server errors (SERVER_)

const (
	UserNotFound      ErrorCode = "USER_NOT_FOUND"
	UserAlreadyExists ErrorCode = "USER_ALREADY_EXISTS"
	UserInactive      ErrorCode = "USER_INACTIVE"
	UserProhibitLogin ErrorCode = "USER_PROHIBIT_LOGIN"
)

User errors (USER_)

const (
	OrgNotFound      ErrorCode = "ORG_NOT_FOUND"
	OrgAlreadyExists ErrorCode = "ORG_ALREADY_EXISTS"
)

Organization errors (ORG_)

const (
	IssueNotFound ErrorCode = "ISSUE_NOT_FOUND"
	IssueClosed   ErrorCode = "ISSUE_CLOSED"
	IssueLocked   ErrorCode = "ISSUE_LOCKED"
)

Issue errors (ISSUE_)

const (
	PRNotFound       ErrorCode = "PR_NOT_FOUND"
	PRAlreadyMerged  ErrorCode = "PR_ALREADY_MERGED"
	PRNotMergeable   ErrorCode = "PR_NOT_MERGEABLE"
	PRWorkInProgress ErrorCode = "PR_WORK_IN_PROGRESS"
)

Pull Request errors (PR_)

const (
	ReleaseNotFound  ErrorCode = "RELEASE_NOT_FOUND"
	ReleaseTagExists ErrorCode = "RELEASE_TAG_EXISTS"
	ReleaseIsDraft   ErrorCode = "RELEASE_IS_DRAFT"
)

Release errors (RELEASE_)

const (
	WebhookNotFound     ErrorCode = "WEBHOOK_NOT_FOUND"
	WebhookDeliveryFail ErrorCode = "WEBHOOK_DELIVERY_FAILED"
)

Webhook errors (WEBHOOK_)

const (
	WikiPageNotFound      ErrorCode = "WIKI_PAGE_NOT_FOUND"
	WikiPageAlreadyExists ErrorCode = "WIKI_PAGE_ALREADY_EXISTS"
	WikiReservedName      ErrorCode = "WIKI_RESERVED_NAME"
	WikiDisabled          ErrorCode = "WIKI_DISABLED"
)

Wiki errors (WIKI_)

func (ErrorCode) Error

func (e ErrorCode) Error() string

Error implements the error interface

func (ErrorCode) HTTPStatus

func (e ErrorCode) HTTPStatus() int

HTTPStatus returns the HTTP status code for an error code

func (ErrorCode) IsValid

func (e ErrorCode) IsValid() bool

IsValid returns true if the error code is registered in the catalog

func (ErrorCode) Message

func (e ErrorCode) Message() string

Message returns the human-readable message for an error code

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the error code as a string

type ValidationError

type ValidationError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Code    string `json:"code,omitempty"`
}

ValidationError represents a field-level validation error

Source Files

  • api_error.go
  • codes.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL