errors

package
v0.17.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides sentinel errors and custom error types for the stackit application. Use errors.Is() and errors.As() to check for specific error types.

Package errors provides error wrapping helpers for consistent error messages.

Index

Constants

This section is empty.

Variables

View Source
var (
	Is     = errors.Is
	As     = errors.As
	New    = errors.New
	Unwrap = errors.Unwrap
)

Standard library error functions wrapped for convenience

View Source
var (
	// ErrNotOnBranch indicates that HEAD is not on a branch
	ErrNotOnBranch = errors.New("not on a branch")

	// ErrNotOnBranchNoBranchSpecified indicates HEAD is not on a branch and no branch was specified
	ErrNotOnBranchNoBranchSpecified = errors.New("not on a branch and no branch specified")

	// ErrBranchNotFound indicates that a branch does not exist
	ErrBranchNotFound = errors.New("branch not found")

	// ErrRebaseConflict indicates that a rebase operation encountered a conflict
	ErrRebaseConflict = errors.New("rebase conflict")

	// ErrRebaseNotInProgress indicates that no rebase is currently in progress
	ErrRebaseNotInProgress = errors.New("no rebase in progress")

	// ErrTrunkOperation indicates an invalid operation on the trunk branch
	ErrTrunkOperation = errors.New("invalid operation on trunk branch")

	// ErrBranchModificationRestricted indicates a branch cannot be modified due to its state (locked or frozen)
	ErrBranchModificationRestricted = errors.New("branch modification restricted")

	// ErrCanceled indicates that an interactive operation was canceled by the user
	ErrCanceled = errors.New("canceled")

	// ErrBack indicates that the user wants to go back to the previous step
	ErrBack = errors.New("back")
)

Sentinel errors for common conditions

Functions

func FailedTo

func FailedTo(action, target string, err error) error

FailedTo wraps an error with a "failed to <action> <target>" message. Returns nil if err is nil, making it safe to use in error return statements.

Example:

return errors.FailedTo("get", "branch revision", err)
// Returns: "failed to get branch revision: <underlying error>"

func Op

func Op(operation string, err error) error

Op wraps an error with an operation name context. Returns nil if err is nil, making it safe to use in error return statements.

Example:

return errors.Op("rebase", err)
// Returns: "rebase: <underlying error>"

func While

func While(action string, err error) error

While wraps an error with context about what action was being performed. Returns nil if err is nil, making it safe to use in error return statements.

Example:

return errors.While("checking branch status", err)
// Returns: "checking branch status: <underlying error>"

func Wrap

func Wrap(err error, format string, args ...any) error

Wrap wraps an error with arbitrary context. Returns nil if err is nil, making it safe to use in error return statements.

Example:

return errors.Wrap(err, "processing branch %s", branchName)
// Returns: "processing branch feature: <underlying error>"

Types

type BranchModificationError

type BranchModificationError struct {
	BranchName string
	LockReason git.LockReason
	IsFrozen   bool
}

BranchModificationError represents an error when a branch cannot be modified

func NewBranchModificationError

func NewBranchModificationError(branchName string, lockReason git.LockReason, frozen bool) *BranchModificationError

NewBranchModificationError creates a new BranchModificationError

func (*BranchModificationError) Error

func (e *BranchModificationError) Error() string

func (*BranchModificationError) Is

func (e *BranchModificationError) Is(target error) bool

Is returns true if the target error is ErrBranchModificationRestricted

func (*BranchModificationError) IsLocked

func (e *BranchModificationError) IsLocked() bool

IsLocked returns true if the branch is locked

type BranchNotFoundError

type BranchNotFoundError struct {
	BranchName string
}

BranchNotFoundError represents an error when a branch is not found

func NewBranchNotFoundError

func NewBranchNotFoundError(branchName string) *BranchNotFoundError

NewBranchNotFoundError creates a new BranchNotFoundError

func (*BranchNotFoundError) Error

func (e *BranchNotFoundError) Error() string

func (*BranchNotFoundError) Is

func (e *BranchNotFoundError) Is(target error) bool

Is returns true if the target error is ErrBranchNotFound

type RebaseConflictError

type RebaseConflictError struct {
	BranchName string
	Message    string
}

RebaseConflictError represents an error when a rebase encounters a conflict

func NewRebaseConflictError

func NewRebaseConflictError(branchName string, message string) *RebaseConflictError

NewRebaseConflictError creates a new RebaseConflictError

func (*RebaseConflictError) Error

func (e *RebaseConflictError) Error() string

func (*RebaseConflictError) Is

func (e *RebaseConflictError) Is(target error) bool

Is returns true if the target error is ErrRebaseConflict

Jump to

Keyboard shortcuts

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