errorhandler

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package errorhandler centralizes Cobra command execution with KSail's error formatting rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandError

type CommandError struct {
	// contains filtered or unexported fields
}

CommandError represents a Cobra execution failure augmented with normalized stderr output.

func NewCommandError

func NewCommandError(message string, cause error) *CommandError

NewCommandError constructs a CommandError with the provided message and cause.

func (*CommandError) Error

func (e *CommandError) Error() string

Error implements the error interface.

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

Unwrap exposes the underlying cause for errors.Is/errors.As consumers.

type DefaultNormalizer

type DefaultNormalizer struct{}

DefaultNormalizer implements Normalizer with the same semantics previously embedded in root.go.

func (DefaultNormalizer) Normalize

func (DefaultNormalizer) Normalize(raw string) string

Normalize trims whitespace, removes redundant "Error:" prefixes, and preserves multi-line usage hints.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor coordinates Cobra execution, capturing stderr output and surfacing aggregated errors.

func NewExecutor

func NewExecutor(opts ...Option) *Executor

NewExecutor constructs an Executor with optional functional options.

func (*Executor) Execute

func (e *Executor) Execute(cmd *cobra.Command) error

Execute runs the provided command while intercepting Cobra's error stream. It returns nil on success, or a *CommandError containing both the normalized message and the original error to preserve error-chain semantics.

type Normalizer

type Normalizer interface {
	Normalize(raw string) string
}

Normalizer transforms raw stderr output captured from Cobra into a final error message.

type Option

type Option func(*Executor)

Option configures an Executor.

func WithNormalizer

func WithNormalizer(normalizer Normalizer) Option

WithNormalizer overrides the default message normalizer used by the executor.

Jump to

Keyboard shortcuts

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