errorcode

package
v1.3.116 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package errorcode provides primitives to interact with the openapi HTTP API.

Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.

This is not autogenerated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenProbableCauses

func FlattenProbableCauses(causes []ProbableCause) (probableCause, suggestedRemediation []string)

FlattenProbableCauses derives the flat lists earlier consumers read from nested causes: each cause's description in order, and each remediation's description walking the causes, then their remediations, in order, with each remediation ID kept the first time it appears. Nil causes yield two empty, non-nil lists.

func ValidateFlatLists

func ValidateFlatLists(causes *[]ProbableCause, probableCause, suggestedRemediation *[]string, prefix string) error

ValidateFlatLists checks that flat lists carried beside nested causes are the lists FlattenProbableCauses derives. Without nested causes the flat lists are unpaired and there is nothing to check. prefix is prepended to the field names, for example "errors[0].".

func ValidateProbableCauses

func ValidateProbableCauses(causes []ProbableCause, path string) error

ValidateProbableCauses checks nested causes: cause IDs are unique, a remediation ID repeated under several causes names one remediation with identical fields, and every automatic or requiresApproval remediation has an action. path prefixes each error's JSON path, for example "probableCauses". It is shared by ErrorDefinition and the event construct's EventError.

Types

type ActionPolicy

type ActionPolicy string

ActionPolicy Whether a client may apply a remediation on its own. `automatic`: the client may run the remediation's `action` without asking and then tells the person it did. `requiresApproval`: the client runs the `action` only after a person approves it. `manual`: a person applies the remediation; a client shows it and never runs anything. An omitted policy is `manual`, and a reader treats a policy it does not know as `manual`, so a remediation is never run by mistake.

const (
	ActionPolicyAutomatic        ActionPolicy = "automatic"
	ActionPolicyManual           ActionPolicy = "manual"
	ActionPolicyRequiresApproval ActionPolicy = "requiresApproval"
)

Defines values for ActionPolicy.

type ContractError

type ContractError struct {
	Path    string
	Message string
}

ContractError is one broken rule of the error contract, with the JSON path of the value that breaks it.

func (*ContractError) Error

func (e *ContractError) Error() string

type ErrorComponent

type ErrorComponent struct {
	// Name The component's name, for example `meshery-server`, `meshkit` or `mesheryctl`. It is the prefix of every code the component owns.
	Name string `json:"name" yaml:"name"`

	// Type The kind of component, for example `component` (Meshery Server), `adapter`, `library` (MeshKit) or `client` (mesheryctl). An open set: a new kind of component needs no schema change.
	Type string `json:"type" yaml:"type"`
}

ErrorComponent The component that owns an error code: the `type` and `name` of its MeshKit `component_info.json`. Codes are unique only within one component.

type ErrorDefinition

type ErrorDefinition struct {
	// Code The full error code, `<component name>-<numericCode>`, for example `meshery-server-1033`. Codes are scoped to the component that owns them and carry no meaning of their own, so a code is unique only together with its component and nothing may be derived from the number alone.
	Code string `json:"code" yaml:"code"`

	// Moniker The name the code has in source, for example `ErrCreatingUUIDInstanceCode` or `ErrApplyManifest`: what MeshKit's export calls `name`. It is not unique across components.
	Moniker string `json:"moniker" yaml:"moniker"`

	// Component The component that owns an error code: the `type` and `name` of its MeshKit `component_info.json`. Codes are unique only within one component.
	Component ErrorComponent `json:"component" yaml:"component"`

	// NumericCode The number at the end of `code`, as a string of digits so leading zeros survive, for example `1033`. MeshKit's `errorutil` allocates it from the component's `component_info.json` and never reuses it.
	NumericCode string `json:"numericCode" yaml:"numericCode"`

	// Severity How severe an error is, as its definition declares. MeshKit's severities map one to one: `Emergency` to `emergency`, `Alert` to `alert`, `Critical` to `critical` and `Fatal` to `fatal`; MeshKit's `None` is an omitted severity. `error`, `warning`, `informational` and `debug` name the less severe levels of the event severity ladder for components that define them. The event that reports an occurrence carries its own `severity`.
	Severity *ErrorSeverity `json:"severity,omitempty" yaml:"severity,omitempty"`

	// ShortDescription One line saying what went wrong, for example `Unable to create UUID instance`. MeshKit's `ShortDescription` lines are joined with `. `. Omitted only for a code whose details the export could not read.
	ShortDescription *string `json:"shortDescription,omitempty" yaml:"shortDescription,omitempty"`

	// LongDescription The full explanation of the error. Omitted when the definition has only text rendered at run time, which MeshKit's `errorutil` cannot export.
	LongDescription *string `json:"longDescription,omitempty" yaml:"longDescription,omitempty"`

	// ProbableCauses What may have caused the error, most likely first, each with the remediations that answer it. Cause ids are unique within the definition. Omitted for a definition that documents no causes, such as a code declared with MeshKit's flat `errors.New`, whose flat lists are then the only record (and are unpaired).
	ProbableCauses *[]ProbableCause `json:"probableCauses,omitempty" yaml:"probableCauses,omitempty"`

	// ProbableCause The flat list of cause descriptions earlier consumers read (MeshKit's `ProbableCause`). When `probableCauses` is present it equals each cause's `description`, in order. Without `probableCauses` it is the definition's only record of its causes, and nothing pairs an entry with an entry of `suggestedRemediation`.
	ProbableCause *[]string `json:"probableCause,omitempty" yaml:"probableCause,omitempty"`

	// SuggestedRemediation The flat list of remediation descriptions earlier consumers read (MeshKit's `SuggestedRemediation`). When `probableCauses` is present it equals every remediation's `description` across the causes, in order, each remediation `id` once (the first time it appears).
	SuggestedRemediation *[]string `json:"suggestedRemediation,omitempty" yaml:"suggestedRemediation,omitempty"`

	// ReferenceURL The stable docs.meshery.io page for this code, for example `https://docs.meshery.io/reference/error-codes/component-meshery-server/errcreatinguuidinstancecode-1001/`. Always present in a published ErrorReferenceIndex; a component's export may omit it, because the docs build assigns it.
	ReferenceURL *string `json:"referenceUrl,omitempty" yaml:"referenceUrl,omitempty"`
}

ErrorDefinition One error code's definition: the registry entry behind a code such as `meshery-server-1033`. It names the situation the code reports and, for each probable cause, the remediations that answer that cause. A definition is not stored by any server and has no endpoints: the component that owns the code declares it in source (MeshKit's `errors.NewV3`), MeshKit's `errorutil` exports it to the component's `*_errors_index.json`, and docs.meshery.io publishes every definition in an ErrorReferenceIndex. It therefore declares no `id`, `createdAt`, `updatedAt` or `deletedAt`; the code is its key. Causes and remediations are nested, never two parallel lists: each remediation sits under the cause it addresses, and one remediation that answers several causes is repeated under each with the same `id`, so the pairing is explicit and the text is defined once. The flat `probableCause` and `suggestedRemediation` lists earlier consumers read are derived from the nesting (see `probableCause`). The rules JSON Schema cannot state - ids unique, a repeated remediation identical, an `action` behind every `automatic` or `requiresApproval` policy, `code` ending in `-<numericCode>` and the flat lists equal to the derivation - are checked by `Validate` in the generated Go package's helper and by `validateErrorDefinition` in the TypeScript package (docs/error-definition-contract.md).

func (ErrorDefinition) FlatLists

func (d ErrorDefinition) FlatLists() (probableCause, suggestedRemediation []string)

FlatLists returns the definition's flat lists: derived from its nested causes when it has them, otherwise the unpaired lists it carries.

func (ErrorDefinition) Validate

func (d ErrorDefinition) Validate() error

Validate checks the rules of a definition that JSON Schema cannot state: code is the component name, a hyphen and numericCode; the nested causes follow ValidateProbableCauses; and flat lists carried beside them equal the derivation. Validate the shape against the schema first. The returned error joins one *ContractError per broken rule, or is nil.

type ErrorReferenceIndex

type ErrorReferenceIndex struct {
	// Errors The definitions, each code once; the published index orders them by `referenceUrl`.
	Errors []ErrorDefinition `json:"errors" yaml:"errors"`

	// GeneratedAt When the docs build generated the index.
	GeneratedAt *time.Time `json:"generatedAt,omitempty" yaml:"generatedAt,omitempty"`

	// SchemaVersion Version of the index format. `2` is this schema, whose entries are ErrorDefinitions. Version `1` was the flat format the docs build first published, whose entries carry `componentType`, `componentName`, `name`, the numeric `code` and the joined `probableCause` and `suggestedRemediation` strings; a reader that meets it reads it as unpaired definitions.
	SchemaVersion ErrorReferenceIndexSchemaVersion `json:"schemaVersion" yaml:"schemaVersion"`
}

ErrorReferenceIndex A list of error definitions, each code once. Published by docs.meshery.io at `https://docs.meshery.io/reference/error-codes/index.json`, it lists every component's codes, and every entry carries its `referenceUrl`; tools and bots validate codes and link to their pages from it. The same format is a component's export in the nested form (MeshKit's `errorutil`, `*_errors_index.json`): that component's definitions, where `referenceUrl` may be absent because the docs build assigns it when it merges the exports. A code is identified by its component and code.

func (ErrorReferenceIndex) Validate

func (x ErrorReferenceIndex) Validate(requireReferenceURL bool) error

Validate checks every definition in the index and that no code is listed twice for one component. Pass requireReferenceURL for the published index, where every entry links to its page; a component's export may omit them.

type ErrorReferenceIndexSchemaVersion

type ErrorReferenceIndexSchemaVersion int

ErrorReferenceIndexSchemaVersion Version of the index format. `2` is this schema, whose entries are ErrorDefinitions. Version `1` was the flat format the docs build first published, whose entries carry `componentType`, `componentName`, `name`, the numeric `code` and the joined `probableCause` and `suggestedRemediation` strings; a reader that meets it reads it as unpaired definitions.

const (
	SchemaVersion2 ErrorReferenceIndexSchemaVersion = 2
)

Defines values for ErrorReferenceIndexSchemaVersion.

type ErrorSeverity

type ErrorSeverity string

ErrorSeverity How severe an error is, as its definition declares. MeshKit's severities map one to one: `Emergency` to `emergency`, `Alert` to `alert`, `Critical` to `critical` and `Fatal` to `fatal`; MeshKit's `None` is an omitted severity. `error`, `warning`, `informational` and `debug` name the less severe levels of the event severity ladder for components that define them. The event that reports an occurrence carries its own `severity`.

const (
	SeverityAlert         ErrorSeverity = "alert"
	SeverityCritical      ErrorSeverity = "critical"
	SeverityDebug         ErrorSeverity = "debug"
	SeverityEmergency     ErrorSeverity = "emergency"
	SeverityError         ErrorSeverity = "error"
	SeverityFatal         ErrorSeverity = "fatal"
	SeverityInformational ErrorSeverity = "informational"
	SeverityWarning       ErrorSeverity = "warning"
)

Defines values for ErrorSeverity.

type ProbableCause

type ProbableCause struct {
	// Description What may have caused the error, for example `The service is not running.`
	Description string `json:"description" yaml:"description"`

	// ID Stable id of the cause, unique within the error's definition, for example `service-not-running`. An event names the causes that apply to one occurrence by this id (`EventError.matchedCauses`), and the docs page links to it, so it never changes once published. Lowercase words joined by hyphens.
	ID string `json:"id" yaml:"id"`

	// Remediations What answers this cause, the most likely fix first. A remediation that also answers another cause is repeated under that cause with the same `id` and identical fields.
	Remediations []Remediation `json:"remediations" yaml:"remediations"`
}

ProbableCause One probable cause of an error, with the remediations that answer it. Remediations are nested under the cause they address, never kept in a parallel list.

type Remediation

type Remediation struct {
	// Action Identifier of an action a client can run to apply this remediation, as dot-separated lowercase words, for example `service.start` or `connection.reconnect`. The client that runs it owns its meaning; the definition only names it. Omitted when only a person can apply the remediation.
	Action *string `json:"action,omitempty" yaml:"action,omitempty"`

	// ActionPolicy Whether a client may apply a remediation on its own. `automatic`: the client may run the remediation's `action` without asking and then tells the person it did. `requiresApproval`: the client runs the `action` only after a person approves it. `manual`: a person applies the remediation; a client shows it and never runs anything. An omitted policy is `manual`, and a reader treats a policy it does not know as `manual`, so a remediation is never run by mistake.
	ActionPolicy *ActionPolicy `json:"actionPolicy,omitempty" yaml:"actionPolicy,omitempty"`

	// Description What to do, written for a person, for example `Start the service.`
	Description string `json:"description" yaml:"description"`

	// ID Stable id of the remediation, unique within the error's definition, for example `start-service`. The same id under two causes is one remediation answering both, so its fields must be identical in each place, and the flattened `suggestedRemediation` list carries it once. Lowercase words joined by hyphens.
	ID string `json:"id" yaml:"id"`
}

Remediation One remediation for a probable cause: what to do, and optionally a machine-readable action a client may run and the policy that says whether it may run it without asking a person.

func (Remediation) EffectivePolicy

func (r Remediation) EffectivePolicy() ActionPolicy

EffectivePolicy is the policy a client acts on: the remediation's own, ActionPolicyManual when it is omitted, and ActionPolicyManual for a value this version does not know, so a remediation is never run by mistake.

Jump to

Keyboard shortcuts

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