apperr

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apperr defines the machine-readable error contract of szwm.

Error codes and exit codes are a public, versioned interface: agents branch on them. Add new values freely, but never change the meaning of existing ones without bumping output.SchemaVersion.

Index

Constants

View Source
const (
	ExitOK          = 0
	ExitInternal    = 1
	ExitUsage       = 2
	ExitAuth        = 3
	ExitForbidden   = 4
	ExitNotFound    = 5
	ExitNoData      = 6
	ExitRateLimited = 7
	ExitUnavailable = 8
	ExitPartial     = 9
	ExitQuota       = 10
	ExitReadOnly    = 11
	ExitFindings    = 12
)

Process exit codes.

Variables

View Source
var Catalog = []Entry{
	{CodeInternal, ExitInternal, false, "Unexpected failure inside szwm."},
	{CodeInvalidArgument, ExitUsage, false, "Bad flag, argument or input value; fix the command, do not retry it unchanged."},
	{CodeConfirmationRequired, ExitUsage, false, "A bulk write needs an explicit --yes; preview it with --dry-run first."},
	{CodeAuthMissing, ExitAuth, false, "No API key could be resolved."},
	{CodeAuthInvalid, ExitAuth, false, "Seznam rejected the API key (HTTP 401)."},
	{CodeForbidden, ExitForbidden, false, "The key lacks access to this URL or write permission (HTTP 403)."},
	{CodeNotFound, ExitNotFound, false, "Seznam has no data for this page or site (HTTP 404)."},
	{CodeNoDataYet, ExitNoData, true, "The request was fine but data is not available yet (HTTP 204); retry after the next database release."},
	{CodeRateLimited, ExitRateLimited, true, "Rate limit reached after retries; wait retry_after_seconds."},
	{CodeServiceUnavailable, ExitUnavailable, true, "Seznam service is down (HTTP 502/503/504)."},
	{CodeNetworkError, ExitUnavailable, true, "Could not reach Seznam (DNS, TLS, connection)."},
	{CodeTimeout, ExitUnavailable, true, "A request or the whole command ran out of time."},
	{CodeBadResponse, ExitUnavailable, true, "Seznam returned a response szwm could not interpret."},
	{CodeAPIError, ExitInternal, false, "Seznam returned an unexpected HTTP error."},
	{CodePartialFailure, ExitPartial, true, "A batch finished only partly; data.items says which URLs need another attempt."},
	{CodeQuotaExhausted, ExitQuota, true, "The estimated daily reindex quota (500) is used up; retry after midnight Europe/Prague."},
	{CodeReadOnly, ExitReadOnly, false, "Read-only mode blocked a write operation."},
	{CodeFindingsThreshold, ExitFindings, false, "`report --fail-on` matched a finding; the report itself succeeded."},
	{CodeDoctorFailed, ExitInternal, false, "At least one `doctor` check failed; data.checks has the fix."},
}

Catalog lists every error code szwm can emit.

Functions

func IsCode

func IsCode(err error, code Code) bool

IsCode reports whether err is an *Error with the given code.

Types

type Code

type Code string

Code is a stable identifier for a failure class.

const (
	CodeInternal             Code = "internal"
	CodeInvalidArgument      Code = "invalid_argument"
	CodeConfirmationRequired Code = "confirmation_required"
	CodeAuthMissing          Code = "auth_missing"
	CodeAuthInvalid          Code = "auth_invalid"
	CodeForbidden            Code = "forbidden"
	CodeNotFound             Code = "not_found"
	CodeNoDataYet            Code = "no_data_yet"
	CodeRateLimited          Code = "rate_limited"
	CodeServiceUnavailable   Code = "service_unavailable"
	CodeNetworkError         Code = "network_error"
	CodeTimeout              Code = "timeout"
	CodeBadResponse          Code = "bad_response"
	CodeAPIError             Code = "api_error"
	CodePartialFailure       Code = "partial_failure"
	CodeQuotaExhausted       Code = "quota_exhausted"
	CodeReadOnly             Code = "read_only"
	CodeFindingsThreshold    Code = "findings_threshold"
	CodeDoctorFailed         Code = "doctor_failed"
)

Stable error codes.

type Entry

type Entry struct {
	Code        Code   `json:"code"`
	ExitCode    int    `json:"exit_code"`
	Retryable   bool   `json:"retryable"`
	Description string `json:"description"`
}

Entry documents one error code. Catalog drives both behaviour and `szwm schema`.

type Error

type Error struct {
	Code              Code   `json:"code"`
	Message           string `json:"message"`
	Hint              string `json:"hint,omitempty"`
	Field             string `json:"field,omitempty"`
	Retryable         bool   `json:"retryable"`
	RetryAfterSeconds int    `json:"retry_after_seconds,omitempty"`
	HTTPStatus        int    `json:"http_status,omitempty"`
	ExitCode          int    `json:"exit_code"`
}

Error is the structured failure object emitted to callers.

func From

func From(err error) *Error

From converts any error into an *Error, wrapping unknown ones as internal.

func New

func New(code Code, format string, args ...any) *Error

New builds an Error whose retryability and exit code come from Catalog.

func Usage

func Usage(field, format string, args ...any) *Error

Usage is shorthand for an invalid_argument error on a named field.

func (*Error) Error

func (e *Error) Error() string

func (*Error) WithField

func (e *Error) WithField(field string) *Error

WithField names the input that caused the error.

func (*Error) WithHint

func (e *Error) WithHint(hint string) *Error

WithHint attaches a suggested next action.

Jump to

Keyboard shortcuts

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