errorhandler

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 4 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 MockNormalizer added in v1.14.0

type MockNormalizer struct {
	mock.Mock
}

MockNormalizer is an autogenerated mock type for the Normalizer type

func NewMockNormalizer added in v1.14.0

func NewMockNormalizer(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockNormalizer

NewMockNormalizer creates a new instance of MockNormalizer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockNormalizer) EXPECT added in v1.14.0

func (*MockNormalizer) Normalize added in v1.14.0

func (_mock *MockNormalizer) Normalize(raw string) string

Normalize provides a mock function for the type MockNormalizer

type MockNormalizer_Expecter added in v1.14.0

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

func (*MockNormalizer_Expecter) Normalize added in v1.14.0

func (_e *MockNormalizer_Expecter) Normalize(raw interface{}) *MockNormalizer_Normalize_Call

Normalize is a helper method to define mock.On call

  • raw string

type MockNormalizer_Normalize_Call added in v1.14.0

type MockNormalizer_Normalize_Call struct {
	*mock.Call
}

MockNormalizer_Normalize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Normalize'

func (*MockNormalizer_Normalize_Call) Return added in v1.14.0

func (*MockNormalizer_Normalize_Call) Run added in v1.14.0

func (*MockNormalizer_Normalize_Call) RunAndReturn added in v1.14.0

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