errutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnectionClosed 表示连接已关闭(正常情况)
	ErrConnectionClosed = errors.New("connection closed")

	// ErrSessionClosed 表示会话已关闭(正常情况)
	ErrSessionClosed = errors.New("session closed")

	// ErrInvalidConfig 表示配置无效
	ErrInvalidConfig = errors.New("invalid configuration")

	// ErrConnectionFailed 表示连接失败
	ErrConnectionFailed = errors.New("connection failed")

	// ErrAuthFailed 表示认证失败
	ErrAuthFailed = errors.New("authentication failed")

	// ErrCommandFailed 表示命令执行失败
	ErrCommandFailed = errors.New("command execution failed")
)

预定义的错误类型

Functions

func ConvertExitError

func ConvertExitError(err error) error

ConvertExitError 将 SSH 退出错误转换为更友好的错误消息

func EnhanceError

func EnhanceError(err error, stdout, stderr string) error

EnhanceError 增强错误信息,添加更多上下文

func HandleCloseError

func HandleCloseError(errp *error, closer io.Closer)

HandleCloseError 处理 defer 中的 close 错误 自动忽略可忽略的错误,合并其他错误到返回值

func IsEOFError

func IsEOFError(err error) bool

IsEOFError 检查是否是 EOF 相关的错误

func IsIgnorableError

func IsIgnorableError(err error) bool

IsIgnorableError 检查错误是否可忽略

func IsRetriableError

func IsRetriableError(err error) bool

IsRetriableError 检查错误是否可重试

func JoinErrors

func JoinErrors(errs ...error) error

JoinErrors 合并多个错误

func SafeClose

func SafeClose(closer io.Closer) error

SafeClose 安全地关闭资源,忽略可忽略的错误 返回需要关注的错误

func SafeCloseMultiple

func SafeCloseMultiple(closers ...io.Closer) error

SafeCloseMultiple 安全地关闭多个资源 返回所有非可忽略的错误的组合

func WrapError

func WrapError(err error, context string) error

WrapError 包装错误并添加上下文信息

Types

type ErrorCategory

type ErrorCategory int

ErrorCategory 错误分类

const (
	// CategoryIgnorable 可忽略的错误(如正常的连接关闭)
	CategoryIgnorable ErrorCategory = iota

	// CategoryRetriable 可重试的错误(如临时网络问题)
	CategoryRetriable

	// CategoryFatal 致命错误(如认证失败)
	CategoryFatal
)

func CategorizeError

func CategorizeError(err error) ErrorCategory

CategorizeError 对错误进行分类

Jump to

Keyboard shortcuts

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