exit

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package exit provides process exit codes and typed errors.

This package defines standard exit codes for nssh and provides ExitError, a typed error that carries both an exit code and message. Commands return ExitError to signal specific failure modes to the shell.

Exit Codes

Standard exit codes follow Unix conventions:

ExitSuccess          = 0    // Successful completion
ExitGeneralError     = 1    // General/unspecified error
ExitConnectionFailed = 2    // SSH connection failed
ExitAuthFailed       = 3    // Authentication failed
ExitHostNotFound     = 4    // Host not in SSH config
ExitVaultError       = 5    // Vault/credential error
ExitNotExecutable    = 126  // Command not executable
ExitNotFound         = 127  // Command not found

Usage

Return an ExitError to exit with a specific code:

if err != nil {
    return &exit.ExitError{Code: exit.ExitConnectionFailed, Message: "timeout"}
}

Or use predefined errors:

return exit.ErrAuthFailed

The main function checks for ExitError and calls os.Exit with the code.

Index

Constants

View Source
const (
	ExitSuccess          = 0
	ExitGeneralError     = 1
	ExitConnectionFailed = 2
	ExitAuthFailed       = 3
	ExitHostNotFound     = 4
	ExitVaultError       = 5
	ExitNotExecutable    = 126
	ExitNotFound         = 127
)

Variables

View Source
var (
	ErrConnectionFailed = &ExitError{Code: ExitConnectionFailed, Message: "connection failed"}
	ErrAuthFailed       = &ExitError{Code: ExitAuthFailed, Message: "authentication failed"}
	ErrHostNotFound     = &ExitError{Code: ExitHostNotFound, Message: "host not found"}
	ErrVault            = &ExitError{Code: ExitVaultError, Message: "vault error"}
)

Predefined errors for common failure modes.

Functions

This section is empty.

Types

type ExitError

type ExitError struct {
	Code    int
	Message string
	Cause   error
}

ExitError represents an error with a specific exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Jump to

Keyboard shortcuts

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