errors

package
v0.0.0-...-ef18e8d Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package errors provides typed errors for the canopy application.

Index

Constants

This section is empty.

Variables

View Source
var (
	WorkspaceNotFound      = &CanopyError{Code: ErrWorkspaceNotFound}
	WorkspaceExists        = &CanopyError{Code: ErrWorkspaceExists}
	WorkspaceLocked        = &CanopyError{Code: ErrWorkspaceLocked}
	RepoNotFound           = &CanopyError{Code: ErrRepoNotFound}
	RepoNotClean           = &CanopyError{Code: ErrRepoNotClean}
	RepoHasUnpushedCommits = &CanopyError{Code: ErrRepoHasUnpushedCommits}
	RepoAlreadyExists      = &CanopyError{Code: ErrRepoAlreadyExists}
	GitOperationFailed     = &CanopyError{Code: ErrGitOperationFailed}
	ConfigInvalid          = &CanopyError{Code: ErrConfigInvalid}
	ConfigValidation       = &CanopyError{Code: ErrConfigValidation}
	UnknownRepository      = &CanopyError{Code: ErrUnknownRepository}
	NotInWorkspace         = &CanopyError{Code: ErrNotInWorkspace}
	CommandFailed          = &CanopyError{Code: ErrCommandFailed}
	InvalidArgument        = &CanopyError{Code: ErrInvalidArgument}
	OperationCancelled     = &CanopyError{Code: ErrOperationCancelled}
	OperationTimeout       = &CanopyError{Code: ErrOperationTimeout}
	IOFailed               = &CanopyError{Code: ErrIOFailed}
	RegistryError          = &CanopyError{Code: ErrRegistryError}
	InternalError          = &CanopyError{Code: ErrInternalError}
	RepoInUse              = &CanopyError{Code: ErrRepoInUse}
	WorkspaceMetadata      = &CanopyError{Code: ErrWorkspaceMetadata}
	NoReposConfigured      = &CanopyError{Code: ErrNoReposConfigured}
	MissingBranchConfig    = &CanopyError{Code: ErrMissingBranchConfig}
	HookFailed             = &CanopyError{Code: ErrHookFailed}
	HookTimeout            = &CanopyError{Code: ErrHookTimeout}
	PathInvalid            = &CanopyError{Code: ErrPathInvalid}
	PathNotDirectory       = &CanopyError{Code: ErrPathNotDirectory}
)

Sentinel errors for use with errors.Is().

Functions

func IsOperationCanceled

func IsOperationCanceled(err error) bool

IsOperationCanceled returns true if err is an operation cancelled error.

func IsOperationTimeout

func IsOperationTimeout(err error) bool

IsOperationTimeout returns true if err is an operation timeout error.

Types

type CanopyError

type CanopyError struct {
	Code    ErrorCode
	Message string
	Cause   error
	Context map[string]string
}

CanopyError is a typed error with code, message, cause, and context.

func NewCommandFailed

func NewCommandFailed(command string, cause error) *CanopyError

NewCommandFailed creates an error for when a command execution fails.

func NewConfigInvalid

func NewConfigInvalid(detail string) *CanopyError

NewConfigInvalid creates an error for invalid configuration.

func NewConfigValidation

func NewConfigValidation(field, detail string) *CanopyError

NewConfigValidation creates an error for configuration validation failures.

func NewContextError

func NewContextError(ctx context.Context, operation, target string) *CanopyError

NewContextError creates the appropriate error based on the context error. Returns NewOperationTimeout if ctx.Err() is DeadlineExceeded, otherwise NewOperationCanceledWithTarget.

func NewHookFailed

func NewHookFailed(index int, command string, exitCode int, repoName, stderr string) *CanopyError

NewHookFailed creates an error for a failed hook execution.

func NewHookTimeout

func NewHookTimeout(index int, command string, timeout time.Duration) *CanopyError

NewHookTimeout creates an error for a hook that timed out.

func NewIOFailed

func NewIOFailed(operation string, cause error) *CanopyError

NewIOFailed creates an error for IO operation failures.

func NewInternalError

func NewInternalError(detail string, cause error) *CanopyError

NewInternalError creates an error for unexpected internal failures.

func NewInvalidArgument

func NewInvalidArgument(name, detail string) *CanopyError

NewInvalidArgument creates an error for invalid input arguments.

func NewMissingBranchConfig

func NewMissingBranchConfig(workspaceID string) *CanopyError

NewMissingBranchConfig creates an error for missing branch configuration.

func NewNoReposConfigured

func NewNoReposConfigured(workspaceID string) *CanopyError

NewNoReposConfigured creates an error for workspaces with no repos.

func NewNotInWorkspace

func NewNotInWorkspace(path string) *CanopyError

NewNotInWorkspace creates an error for when a command is run outside a workspace.

func NewOperationCanceledWithTarget

func NewOperationCanceledWithTarget(operation, target string) *CanopyError

NewOperationCanceledWithTarget creates an error for context-cancelled operations that includes what was being operated on (e.g., "clone", "https://github.com/...").

func NewOperationCancelled

func NewOperationCancelled(operation string) *CanopyError

NewOperationCancelled creates an error for user-cancelled operations.

func NewOperationTimeout

func NewOperationTimeout(operation, target string) *CanopyError

NewOperationTimeout creates an error for operations that timed out.

func NewPathInvalid

func NewPathInvalid(path, reason string) *CanopyError

NewPathInvalid creates an error for invalid path values.

func NewPathNotDirectory

func NewPathNotDirectory(path string) *CanopyError

NewPathNotDirectory creates an error for paths that should be directories but aren't.

func NewRegistryError

func NewRegistryError(operation, detail string, cause error) *CanopyError

NewRegistryError creates an error for registry operations.

func NewRepoAlreadyExists

func NewRepoAlreadyExists(repoName, workspaceID string) *CanopyError

NewRepoAlreadyExists creates an error for when a repo already exists in a workspace.

func NewRepoHasUnpushedCommits

func NewRepoHasUnpushedCommits(repoName string, count int, action string) *CanopyError

NewRepoHasUnpushedCommits creates an error for when a repository has unpushed commits.

func NewRepoInUse

func NewRepoInUse(name string, workspaces []string) *CanopyError

NewRepoInUse creates an error for when a repo is used by workspaces.

func NewRepoNotClean

func NewRepoNotClean(repoName, action string) *CanopyError

NewRepoNotClean creates an error for when a repository has uncommitted changes.

func NewRepoNotFound

func NewRepoNotFound(name string) *CanopyError

NewRepoNotFound creates an error for when a repository is not found.

func NewUnknownRepository

func NewUnknownRepository(identifier string, userRequested bool) *CanopyError

NewUnknownRepository creates an error for unresolvable repository identifiers.

func NewWorkspaceExists

func NewWorkspaceExists(id string) *CanopyError

NewWorkspaceExists creates an error for when a workspace already exists.

func NewWorkspaceLocked

func NewWorkspaceLocked(id string) *CanopyError

NewWorkspaceLocked creates an error for when a workspace is locked.

func NewWorkspaceMetadataError

func NewWorkspaceMetadataError(workspaceID, operation string, cause error) *CanopyError

NewWorkspaceMetadataError creates an error for workspace metadata operations.

func NewWorkspaceNotFound

func NewWorkspaceNotFound(id string) *CanopyError

NewWorkspaceNotFound creates an error for when a workspace is not found.

func Wrap

func Wrap(code ErrorCode, message string, cause error) *CanopyError

Wrap wraps an error with a CanopyError, preserving the cause.

func WrapGitError

func WrapGitError(err error, operation string) *CanopyError

WrapGitError wraps a git operation error. If the error is already an operation cancelled or timeout error, it returns the original error to preserve the specific error type.

func (*CanopyError) Error

func (e *CanopyError) Error() string

Error implements the error interface.

func (*CanopyError) Is

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

Is checks if the target error has the same error code.

func (*CanopyError) Unwrap

func (e *CanopyError) Unwrap() error

Unwrap returns the underlying cause for use with errors.Unwrap.

func (*CanopyError) WithContext

func (e *CanopyError) WithContext(key, value string) *CanopyError

WithContext returns a copy of the error with additional context key-value pairs. This creates a shallow copy to avoid mutating sentinel errors.

type ErrorCode

type ErrorCode string

ErrorCode identifies the type of error.

const (
	ErrWorkspaceNotFound      ErrorCode = "WORKSPACE_NOT_FOUND"
	ErrWorkspaceExists        ErrorCode = "WORKSPACE_EXISTS"
	ErrWorkspaceLocked        ErrorCode = "WORKSPACE_LOCKED"
	ErrRepoNotFound           ErrorCode = "REPO_NOT_FOUND"
	ErrRepoNotClean           ErrorCode = "REPO_NOT_CLEAN"
	ErrRepoAlreadyExists      ErrorCode = "REPO_ALREADY_EXISTS"
	ErrRepoHasUnpushedCommits ErrorCode = "REPO_HAS_UNPUSHED_COMMITS"
	ErrGitOperationFailed     ErrorCode = "GIT_OPERATION_FAILED"
	ErrConfigInvalid          ErrorCode = "CONFIG_INVALID"
	ErrConfigValidation       ErrorCode = "CONFIG_VALIDATION"
	ErrUnknownRepository      ErrorCode = "UNKNOWN_REPOSITORY"
	ErrNotInWorkspace         ErrorCode = "NOT_IN_WORKSPACE"
	ErrCommandFailed          ErrorCode = "COMMAND_FAILED"
	ErrInvalidArgument        ErrorCode = "INVALID_ARGUMENT"
	ErrOperationCancelled     ErrorCode = "OPERATION_CANCELLED"
	ErrOperationTimeout       ErrorCode = "OPERATION_TIMEOUT"
	ErrIOFailed               ErrorCode = "IO_FAILED"
	ErrRegistryError          ErrorCode = "REGISTRY_ERROR"
	ErrInternalError          ErrorCode = "INTERNAL_ERROR"
	ErrRepoInUse              ErrorCode = "REPO_IN_USE"
	ErrWorkspaceMetadata      ErrorCode = "WORKSPACE_METADATA_ERROR"
	ErrNoReposConfigured      ErrorCode = "NO_REPOS_CONFIGURED"
	ErrMissingBranchConfig    ErrorCode = "MISSING_BRANCH_CONFIG"
	ErrHookFailed             ErrorCode = "HOOK_FAILED"
	ErrHookTimeout            ErrorCode = "HOOK_TIMEOUT"
	ErrPathInvalid            ErrorCode = "PATH_INVALID"
	ErrPathNotDirectory       ErrorCode = "PATH_NOT_DIRECTORY"
)

Error codes for domain errors.

Jump to

Keyboard shortcuts

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