Documentation
¶
Index ¶
Constants ¶
const ( ExitSuccess = 0 // Command completed successfully ExitGeneralError = 1 // Unclassified/unexpected error (default) ExitUsageError = 2 // Bad flags, invalid selectors, missing args, unknown commands ExitAuthFailure = 3 // HTTP 401/403, missing/invalid credentials ExitPartialFailure = 4 // Some resources succeeded, others failed (push/pull/delete/validate) ExitCancelled = 5 // User cancelled (SIGINT) or context.Canceled ExitVersionIncompatible = 6 // Grafana version < 12 )
Exit code taxonomy for gcx.
These codes let scripts and CI pipelines distinguish between error categories without parsing stderr text.
Variables ¶
This section is empty.
Functions ¶
func SameRenderedMessage ¶
SameRenderedMessage reports whether details and parent render the same message, used to suppress redundant output in error formatting.
Types ¶
type DetailedError ¶
type DetailedError struct {
// Summary is a one-liner that briefly describes the error.
// This field is expected to NOT be empty.
Summary string
// Details holds additional information on the error.
// Optional.
Details string
// Parent holds a reference to a parent error.
// Optional.
Parent error
// Suggestions holds list of suggestions related to the error.
// Optional.
Suggestions []string
// DocsLink holds a link to a documentation page related to the error.
// Optional.
DocsLink string
// ExitCode indicates which exit code should be used as a result of this error.
// If nil, 1 should be used.
// Optional.
ExitCode *int
}
DetailedError is used to describe errors in a human-friendly way. It can be used to format errors as follows:
Error: File not found │ │ could not read './cmd/config/testdata/config.yamls' │ ├─ Details: │ │ open ./cmd/config/testdata/config.yamls: no such file or directory │ ├─ Suggestions: │ │ • Check for typos in the command's arguments │ ├─ Learn more: │ │ https://example.com/docs/errors.html#some-error │ └─
func (DetailedError) Error ¶
func (e DetailedError) Error() string
func (DetailedError) WriteJSON ¶
func (e DetailedError) WriteJSON(w io.Writer, exitCode int) error
WriteJSON writes the error as a JSON object to the given writer. The output shape is: {"error": {"summary": "...", "exitCode": N, ...}} Optional fields (details, suggestions, docsLink) are omitted when empty. The exitCode in JSON matches the process exit code derived from ExitCode. Box-drawing characters in Details and Suggestions are replaced with plain ASCII equivalents as a defensive measure against rendering artefacts in agent-mode JSON output.
func (DetailedError) WriteJSONWithItems ¶
WriteJSONWithItems writes a combined {"items": [...], "error": {...}} envelope to w. Used for partial failures where some results succeeded and others failed — a single JSON object carries both the partial results and the error context.
type PartialFailureError ¶
type PartialFailureError struct {
Total int
Failed int
Op string // "push", "pull", "delete", "validate"
}
PartialFailureError indicates that a batch operation completed but some resources failed. Commands should return this instead of a plain fmt.Errorf so that the error converter can set exit code 4.
func NewPartialFailureError ¶
func NewPartialFailureError(op string, total, failed int) *PartialFailureError
NewPartialFailureError creates a PartialFailureError for a batch operation where some resources failed.
func (*PartialFailureError) Error ¶
func (e *PartialFailureError) Error() string