error

package
v1.0.28 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: 14 Imported by: 0

Documentation

Index

Constants

View Source
const IndexFileSuffix = "_errors_index.json"

IndexFileSuffix names the nested export: <app>_errors_index.json, the component's error definitions as a schemas ErrorReferenceIndex (schemaVersion 2). The legacy <app>_errors_export.json keeps its shape, because the Meshery docs build reads it as is.

Variables

This section is empty.

Functions

func Definition added in v1.0.25

func Definition(componentInfo *component.Info, numericCode string, name string, details *Error) errorcode.ErrorDefinition

Definition returns the schemas ErrorDefinition of one exported error. details is the error's analysis entry, nil when errorutil found no (or duplicate) details for it.

func Export

func Export(componentInfo *component.Info, infoAll *InfoAll, outputDir string) error

func ExportIndex added in v1.0.25

func ExportIndex(componentInfo *component.Info, exported map[string]Error, infoAll *InfoAll, outputDir string) error

ExportIndex writes the component's exported errors as a schemas ErrorReferenceIndex to <app>_errors_index.json. exported is the legacy export's entries; each definition's numericCode comes from its entry's Code. A definition that breaks the schemas contract (for example a code name the moniker pattern rejects) is reported as an error and left out, so the file always validates; referenceUrl is left for the docs build to assign.

func InvalidDefinitions added in v1.0.25

func InvalidDefinitions(infoAll *InfoAll) map[string][]string

InvalidDefinitions returns the errors.NewV3 definitions errorutil rejected, by error name, with the problems found. errorutil leaves them out of both exports, and analyze and update fail while any remain.

func SummarizeAnalysis

func SummarizeAnalysis(componentInfo *component.Info, infoAll *InfoAll, outputDir string) error

SummarizeAnalysis summarizes the analysis and writes it to the specified output directory.

Types

type Error

type Error struct {
	Name                 string `yaml:"name" json:"name"`                                   // the name of the error code variable, e.g. "ErrInstallMesh", not guaranteed to be unique as it is package scoped
	Code                 string `yaml:"code" json:"code"`                                   // the code, an int, but exported as string, e.g. "1001", guaranteed to be unique per component-type:component-name
	Severity             string `yaml:"severity" json:"severity"`                           // a textual representation of the type Severity (errors/types.go), i.e. "none", "alert", etc
	LongDescription      string `yaml:"long_description" json:"long_description"`           // might contain newlines (JSON encoded)
	ShortDescription     string `yaml:"short_description" json:"short_description"`         // might contain newlines (JSON encoded)
	ProbableCause        string `yaml:"probable_cause" json:"probable_cause"`               // might contain newlines (JSON encoded)
	SuggestedRemediation string `yaml:"suggested_remediation" json:"suggested_remediation"` // might contain newlines (JSON encoded)
	// ProbableCauses is the nested form of an errors.NewV3 definition: each cause with the remediations that
	// answer it, in the schemas error construct's ProbableCause shape (meshery/schemas#1334). Omitted for New and
	// NewV2 definitions, so the export's legacy shape is unchanged. A NewV3 definition errorutil rejected is not
	// exported at all.
	ProbableCauses []errorcode.ProbableCause `yaml:"probableCauses,omitempty" json:"probableCauses,omitempty"`

	// Constructor is the MeshKit constructor of the definition: New, NewV2 or NewV3.
	Constructor string `yaml:"constructor,omitempty" json:"constructor,omitempty"`
	// Problems lists why errorutil rejects a NewV3 definition. Each is reported as an error, and a definition with
	// problems is left out of both exports.
	Problems []string `yaml:"problems,omitempty" json:"problems,omitempty"`
	// Lines holds the literal lines of each description list, before they are joined with newlines above.
	Lines Lines `yaml:"-" json:"-"`
}

Error is used to export Error for e.g. documentation purposes.

Type Error (errors/types.go) is not reused in order to avoid tight coupling between code and documentation of errors, e.g. on Meshery website. It is good practice not to use internal data types in integrations; one should in general transform between internal and external models. DDD calls this anti-corruption layer. One reason is that one might like to have a different representation externally, e.g. severity 'info' instead of '1'. Another one is that it is often desirable to be able to change the internal representation without the need for the consumer (in this case, the meshery doc) to have to adjust quickly in order to be able to handle updated content. The lifecycles of producers and consumers should not be tightly coupled.

type Info

type Info struct {
	Name          string `yaml:"name" json:"name"`
	OldCode       string `yaml:"old_code" json:"old_code"`
	Code          string `yaml:"code" json:"code"`
	CodeIsLiteral bool   `yaml:"code_is_literal" json:"code_is_literal"`
	CodeIsInt     bool   `yaml:"code_is_int" json:"code_is_int"`
	Path          string `yaml:"path" json:"path"`
}

type InfoAll

type InfoAll struct {
	Entries              []Info             `yaml:"entries" json:"entries"`                                // raw entries
	LiteralCodes         map[string][]Info  `yaml:"literal_codes" json:"literal_codes"`                    // entries with literal codes
	CallExprCodes        []Info             `yaml:"call_expr_codes" json:"call_expr_codes"`                // entries with call expressions
	DeprecatedNewDefault []string           `yaml:"deprecated_new_default" json:"deprecated_new_default" ` // list of files with usage of deprecated NewDefault func
	Errors               map[string][]Error `yaml:"errors_raw" json:"errors_raw"`                          // map of detected errors created using errors.New(...). The key is the error name, more than 1 entry in the list is a duplication error.
}

func NewInfoAll

func NewInfoAll() *InfoAll

type Lines added in v1.0.25

type Lines struct {
	ShortDescription     []string
	LongDescription      []string
	ProbableCause        []string
	SuggestedRemediation []string
}

Lines holds the literal lines of an error definition's string lists.

Jump to

Keyboard shortcuts

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