errors

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors: parse stage error codes.

These constants are the stable wire format the frontend uses to map a failure to a localized "what to do about it" message. Adding a new code is non-breaking; renaming an existing one requires a coordinated frontend release because the i18n keys are looked up by code.

Codes are SCREAMING_SNAKE so they survive JSON case transforms and look distinct from Go identifiers in logs/dashboards.

Index

Constants

View Source
const (
	// ErrCodeDocReaderTimeout — DocReader RPC exceeded
	// WEKNORA_DOCREADER_CALL_TIMEOUT (default 30m). Suggest splitting
	// large files or checking docreader load.
	ErrCodeDocReaderTimeout = "DOCREADER_TIMEOUT"

	// ErrCodeDocReaderUnavailable — no DocReader configured for the
	// requested file type / engine, or the service refused connection.
	ErrCodeDocReaderUnavailable = "DOCREADER_UNAVAILABLE"

	// ErrCodeDocReaderParseFailed — DocReader returned an explicit parse
	// error (encoding, corrupted file, OCR engine crash, ...).
	ErrCodeDocReaderParseFailed = "DOCREADER_PARSE_FAILED"

	// ErrCodeChunkingFailed — text chunking step itself failed (rare;
	// usually only on extreme-size inputs).
	ErrCodeChunkingFailed = "CHUNKING_FAILED"

	// ErrCodeEmbeddingRateLimit — embedding provider returned 429 or
	// equivalent. Suggest retrying later or scaling out.
	ErrCodeEmbeddingRateLimit = "EMBEDDING_RATE_LIMIT"

	// ErrCodeEmbeddingProviderFail — non-rate-limit embedding error
	// (auth, model not found, bad input). Usually permanent without
	// config changes.
	ErrCodeEmbeddingProviderFail = "EMBEDDING_PROVIDER_FAIL"

	// ErrCodeVectorStoreWriteFailed — chunks embedded fine but the
	// vector DB write failed (quota, connectivity, schema mismatch).
	ErrCodeVectorStoreWriteFailed = "VECTORSTORE_WRITE_FAILED"

	// ErrCodeMultimodalVLMFailed — a single image's OCR or caption call
	// failed. Note: per-image failures don't fail the whole parent;
	// see image_multimodal.go finalize-on-last-attempt.
	ErrCodeMultimodalVLMFailed = "MULTIMODAL_VLM_FAILED"

	// ErrCodeMultimodalAllFailed — every image task hit dead-letter.
	// The parent still completes (caption / OCR is optional content),
	// but stage status is marked failed so the UI can warn.
	ErrCodeMultimodalAllFailed = "MULTIMODAL_ALL_FAILED"

	// ErrCodeTaskTimeout — asynq retry budget exhausted. Used by the
	// dead-letter callback when promoting a task failure into a stage
	// failure. Distinct from DocReaderTimeout: this is the asynq-level
	// timeout (whole task), not the docreader-call-level timeout.
	ErrCodeTaskTimeout = "TASK_TIMEOUT"

	// ErrCodeTaskStalled — housekeeping found no progress for longer than
	// the stale threshold with nothing left queued, and failed the row.
	ErrCodeTaskStalled = "TASK_STALLED"

	// ErrCodeUnknown — fallback when a wrapped error doesn't classify.
	// The full message is still recorded in error_detail so operators
	// can debug; the UI shows a generic "see admin" hint.
	ErrCodeUnknown = "UNKNOWN"
)

Variables

View Source
var (
	// ErrSessionNotFound session not found error
	ErrSessionNotFound = errors.New("session not found")
	// ErrSessionExpired session expired error
	ErrSessionExpired = errors.New("session expired")
	// ErrSessionLimitExceeded session limit exceeded error
	ErrSessionLimitExceeded = errors.New("session limit exceeded")
	// ErrInvalidSessionID invalid session ID error
	ErrInvalidSessionID = errors.New("invalid session id")
	// ErrInvalidTenantID invalid tenant ID error
	ErrInvalidTenantID = errors.New("invalid tenant id")
)

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Code     ErrorCode `json:"code"`
	Message  string    `json:"message"`
	Details  any       `json:"details,omitempty"`
	HTTPCode int       `json:"-"`
}

AppError defines the application error structure

func IsAppError

func IsAppError(err error) (*AppError, bool)

IsAppError checks if the error is an AppError type

func NewAgentInvalidMaxIterationsError

func NewAgentInvalidMaxIterationsError() *AppError

func NewAgentInvalidTemperatureError

func NewAgentInvalidTemperatureError() *AppError

func NewAgentMissingAllowedToolsError

func NewAgentMissingAllowedToolsError() *AppError

func NewAgentMissingThinkingModelError

func NewAgentMissingThinkingModelError() *AppError

Agent related errors

func NewBadRequestError

func NewBadRequestError(message string) *AppError

NewBadRequestError creates a bad request error

func NewConflictError

func NewConflictError(message string) *AppError

NewConflictError creates a conflict error

func NewForbiddenError

func NewForbiddenError(message string) *AppError

NewForbiddenError creates a forbidden error

func NewInternalServerError

func NewInternalServerError(message string) *AppError

NewInternalServerError creates an internal server error

func NewModelInUseError

func NewModelInUseError(message string, details any) *AppError

NewModelInUseError creates the typed HTTP 400 returned when active tenant resources still reference a model.

func NewNotFoundError

func NewNotFoundError(message string) *AppError

NewNotFoundError creates a not found error

func NewServiceUnavailableError

func NewServiceUnavailableError(message string) *AppError

NewServiceUnavailableError creates a service unavailable (503) error. Used for transient failures where the caller can retry.

func NewTenantAlreadyExistsError

func NewTenantAlreadyExistsError() *AppError

NewTenantAlreadyExistsError creates a tenant already exists error

func NewTenantCreationDisabledError

func NewTenantCreationDisabledError() *AppError

NewTenantCreationDisabledError reports a deployment-policy denial for ordinary self-service tenant creation.

func NewTenantInactiveError

func NewTenantInactiveError() *AppError

NewTenantInactiveError creates a tenant inactive error

func NewTenantNotFoundError

func NewTenantNotFoundError() *AppError

Tenant related errors

func NewTooManyRequestsError

func NewTooManyRequestsError(message string) *AppError

NewTooManyRequestsError creates a 429 error, used by quota-style guards (e.g. per-user self-service tenant creation cap).

func NewUnauthorizedError

func NewUnauthorizedError(message string) *AppError

NewUnauthorizedError creates an unauthorized error

func NewValidationError

func NewValidationError(message string) *AppError

NewValidationError creates a validation error

func NewVectorStoreBindingInvalidError

func NewVectorStoreBindingInvalidError(message string) *AppError

NewVectorStoreBindingInvalidError signals that a knowledge base create request referenced a vector store that does not exist under the caller's tenant (or carried a malformed UUID). The user-facing message is intentionally generic to avoid enumeration oracles — see the structured log at the call site for the tenant/store pair.

func NewVectorStoreUnavailableError

func NewVectorStoreUnavailableError(message string) *AppError

NewVectorStoreUnavailableError signals that the requested vector store row exists in the database but is not currently wired into the in-memory engine registry (factory failure on CreateStore, dynamic config error, or stale state after a connection-config rotation).

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface

func (*AppError) WithDetails

func (e *AppError) WithDetails(details any) *AppError

WithDetails adds error details

type ErrorCode

type ErrorCode int

ErrorCode defines the error code type

const (
	// Common error codes (1000-1999)
	ErrBadRequest         ErrorCode = 1000
	ErrUnauthorized       ErrorCode = 1001
	ErrForbidden          ErrorCode = 1002
	ErrNotFound           ErrorCode = 1003
	ErrMethodNotAllowed   ErrorCode = 1004
	ErrConflict           ErrorCode = 1005
	ErrTooManyRequests    ErrorCode = 1006
	ErrInternalServer     ErrorCode = 1007
	ErrServiceUnavailable ErrorCode = 1008
	ErrTimeout            ErrorCode = 1009
	ErrValidation         ErrorCode = 1010

	// Tenant related error codes (2000-2099)
	ErrTenantNotFound         ErrorCode = 2000
	ErrTenantAlreadyExists    ErrorCode = 2001
	ErrTenantInactive         ErrorCode = 2002
	ErrTenantNameRequired     ErrorCode = 2003
	ErrTenantInvalidStatus    ErrorCode = 2004
	ErrTenantCreationDisabled ErrorCode = 2005

	// Agent related error codes (2100-2199)
	ErrAgentMissingThinkingModel ErrorCode = 2100
	ErrAgentMissingAllowedTools  ErrorCode = 2101
	ErrAgentInvalidMaxIterations ErrorCode = 2102
	ErrAgentInvalidTemperature   ErrorCode = 2103

	// VectorStore binding related error codes (2200-2299).
	// Both map to HTTP 400 with a generic message; the typed code lets
	// clients distinguish "wrong UUID / cross-tenant" from "store exists
	// but is currently unavailable" without parsing the message text.
	ErrVectorStoreBindingInvalid ErrorCode = 2200
	ErrVectorStoreUnavailable    ErrorCode = 2201

	// Model lifecycle errors (2300-2399).
	// The dedicated code lets clients render structured usage details without
	// parsing the backwards-compatible English error message.
	ErrModelInUse ErrorCode = 2300
)

System error codes

Jump to

Keyboard shortcuts

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