errors

package
v0.9.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Copyright (c) 2025 Nexlayer. All rights reserved.n// Use of this source code is governed by an MIT-stylen// license that can be found in the LICENSE file.nn Package errors provides standardized error types and utilities for the Nexlayer CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As is a wrapper around errors.As to handle unwrapping properly

func IsErrorType

func IsErrorType(err error, errType ErrorType) bool

IsErrorType checks if an error is of a specific type

Types

type Error

type Error struct {
	Cause   error                  `json:"-"`
	Details map[string]interface{} `json:"details,omitempty"`
	Type    ErrorType              `json:"type"`
	Message string                 `json:"message"`
	Code    string                 `json:"code,omitempty"`
	Field   string                 `json:"field,omitempty"`
}

Error represents a structured error with context

func InternalError

func InternalError(message string, cause error) *Error

InternalError creates a new internal error

func NetworkError

func NetworkError(message string, cause error) *Error

NetworkError creates a new network error

func New

func New(errType ErrorType, message string) *Error

New creates a new error with the given type and message

func NewInvalidNameError

func NewInvalidNameError(name, field string) *Error

NewInvalidNameError creates a new invalid name error

func NewInvalidPortError

func NewInvalidPortError(port interface{}, message string) *Error

NewInvalidPortError creates a new invalid port error

func NewInvalidVolumeError

func NewInvalidVolumeError(volume, reason string) *Error

NewInvalidVolumeError creates a new invalid volume error

func NewMissingImageError

func NewMissingImageError(podName string) *Error

NewMissingImageError creates a new missing image error

func NewUnsupportedOSError

func NewUnsupportedOSError(os string) *Error

NewUnsupportedOSError creates a new unsupported OS error

func Newf

func Newf(errType ErrorType, format string, args ...interface{}) *Error

Newf creates a new error with the given type and formatted message

func SystemError

func SystemError(message string, cause error) *Error

SystemError creates a new system error

func UserError

func UserError(message string, cause error) *Error

UserError creates a new user error

func Wrap

func Wrap(err error, errType ErrorType, message string) *Error

Wrap wraps an existing error with a new error type and message

func Wrapf

func Wrapf(err error, errType ErrorType, format string, args ...interface{}) *Error

Wrapf wraps an existing error with a new error type and formatted message

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

func (*Error) Is

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

Is checks if this error is of the given type

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying cause

func (*Error) WithCode

func (e *Error) WithCode(code string) *Error

WithCode adds an error code to the error

func (*Error) WithDetails

func (e *Error) WithDetails(details map[string]interface{}) *Error

WithDetails adds additional context to the error

func (*Error) WithField

func (e *Error) WithField(field string) *Error

WithField adds a field name to the error

type ErrorType

type ErrorType string

ErrorType represents the type of error

const (
	// Common error types
	ErrorTypeInput      ErrorType = "input_error"
	ErrorTypeValidation ErrorType = "validation_error"
	ErrorTypeNetwork    ErrorType = "network_error"
	ErrorTypePermission ErrorType = "permission_error"
	ErrorTypeConfig     ErrorType = "config_error"
	ErrorTypeInternal   ErrorType = "internal_error"
	ErrorTypeUnknown    ErrorType = "unknown_error"

	// Specific error types
	ErrorTypeInvalidPort   ErrorType = "invalid_port"
	ErrorTypeMissingImage  ErrorType = "missing_image"
	ErrorTypeInvalidVolume ErrorType = "invalid_volume"
	ErrorTypeInvalidName   ErrorType = "invalid_name"
	ErrorTypeUnsupportedOS ErrorType = "unsupported_os"
)

func ErrorTypeFromString

func ErrorTypeFromString(s string) ErrorType

ErrorTypeFromString converts a string to an ErrorType

Jump to

Keyboard shortcuts

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