errors

package
v9.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides unified error types for RADIUS authentication and accounting. It follows Go's error handling philosophy with typed errors for metrics and logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAcctError

func IsAcctError(err error) bool

IsAcctError checks whether the error is an accounting error

func IsAuthError

func IsAuthError(err error) bool

IsAuthError checks whether the error is an authentication error

func JoinErrors

func JoinErrors(errs ...error) error

JoinErrors combines multiple errors into a single error. Useful for collecting errors from multiple guards.

func NewAcctDropError

func NewAcctDropError(message string) error

NewAcctDropError creates an accounting drop error

func NewAcctError

func NewAcctError(metricsType string, message string) error

NewAcctError creates an accounting error. Parameters:

  • metricsType: The metrics key for monitoring (e.g., app.MetricsRadiusAcctDrop)
  • message: Human-readable error message

func NewAcctErrorWithCause

func NewAcctErrorWithCause(metricsType, message string, cause error) error

NewAcctErrorWithCause creates an accounting error wrapping an underlying cause.

func NewAcctErrorWithStage

func NewAcctErrorWithStage(metricsType, message, stage string) error

NewAcctErrorWithStage creates an accounting error with stage information.

func NewAcctNasNotFoundError

func NewAcctNasNotFoundError(ip, identifier string) error

NewAcctNasNotFoundError creates an error when NAS is not found for accounting

func NewAcctUsernameEmptyError

func NewAcctUsernameEmptyError() error

NewAcctUsernameEmptyError creates an error for empty username in accounting

func NewAuthError

func NewAuthError(metricsType string, message string) error

NewAuthError creates an authentication error. Parameters:

  • metricsType: The metrics key for monitoring (e.g., app.MetricsRadiusRejectNotExists)
  • message: Human-readable error message

func NewAuthErrorWithCause

func NewAuthErrorWithCause(metricsType, message string, cause error) error

NewAuthErrorWithCause creates an authentication error wrapping an underlying cause.

func NewAuthErrorWithStage

func NewAuthErrorWithStage(metricsType, message, stage string) error

NewAuthErrorWithStage creates an authentication error with stage information. This is useful for tracking where in the pipeline an error occurred.

func NewError

func NewError(message string) error

NewError creates a generic non-typed error

func NewMacBindError

func NewMacBindError() error

NewMacBindError creates an error for MAC address binding failures

func NewOnlineLimitError

func NewOnlineLimitError(message string) error

NewOnlineLimitError creates an error when online session limit is exceeded

func NewPasswordMismatchError

func NewPasswordMismatchError() error

NewPasswordMismatchError creates an error for password validation failures

func NewUnauthorizedNasError

func NewUnauthorizedNasError(ip, identifier string, err error) error

NewUnauthorizedNasError creates an error for unauthorized NAS access

func NewUserDisabledError

func NewUserDisabledError() error

NewUserDisabledError creates an error for disabled user accounts

func NewUserExpiredError

func NewUserExpiredError() error

NewUserExpiredError creates an error for expired user accounts

func NewUserNotExistsError

func NewUserNotExistsError() error

NewUserNotExistsError creates an error for non-existent users

func NewUsernameEmptyError

func NewUsernameEmptyError() error

NewUsernameEmptyError creates an error for empty username

func NewVlanBindError

func NewVlanBindError() error

NewVlanBindError creates an error for VLAN binding failures

func WrapAcctError

func WrapAcctError(metricsType string, err error) error

WrapAcctError converts a general error into an AcctError If the error is already an AcctError, it returns it unchanged

func WrapAuthError

func WrapAuthError(metricsType string, err error) error

WrapAuthError converts a general error into an AuthError If the error is already an AuthError, it returns it unchanged

func WrapError

func WrapError(metricsType string, err error) error

WrapError converts a general error into an AuthError (deprecated, use WrapAuthError) Kept for backward compatibility

Types

type AcctError

type AcctError struct {
	MetricsType string // Metrics key for Prometheus/monitoring
	Message     string // Human-readable error message
	ErrorStage  string // Processing stage where error occurred (optional)
	Cause       error  // Underlying error (optional)
}

AcctError represents a RADIUS accounting error with metrics support. Use this type for all accounting-related errors.

func GetAcctError

func GetAcctError(err error) (*AcctError, bool)

GetAcctError retrieves accounting error details using errors.As

func (*AcctError) Error

func (e *AcctError) Error() string

func (*AcctError) MetricsKey

func (e *AcctError) MetricsKey() string

MetricsKey implements RadiusError interface

func (*AcctError) Stage

func (e *AcctError) Stage() string

Stage implements RadiusError interface

func (*AcctError) Unwrap

func (e *AcctError) Unwrap() error

Unwrap returns the underlying error for errors.Is/As support

type AuthError

type AuthError struct {
	MetricsType string // Metrics key for Prometheus/monitoring
	Message     string // Human-readable error message
	ErrorStage  string // Pipeline stage where error occurred (optional)
	Cause       error  // Underlying error (optional)
}

AuthError represents a RADIUS authentication error with metrics support. Use this type for all authentication-related errors to ensure consistent error handling and metrics reporting.

func GetAuthError

func GetAuthError(err error) (*AuthError, bool)

GetAuthError retrieves authentication error details using errors.As

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) MetricsKey

func (e *AuthError) MetricsKey() string

MetricsKey implements RadiusError interface

func (*AuthError) Stage

func (e *AuthError) Stage() string

Stage implements RadiusError interface

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

Unwrap returns the underlying error for errors.Is/As support

type AuthResult

type AuthResult struct {
	Success     bool        // Whether the stage completed successfully
	Err         error       // Error if Success is false
	ShouldStop  bool        // Whether pipeline execution should stop (success or handled error)
	Response    interface{} // Optional response data to pass to next stage
	MetricsType string      // Metrics key for tracking
}

AuthResult represents the outcome of an authentication pipeline stage. It provides a structured way to communicate results without using panic.

func NewAuthErrorResult

func NewAuthErrorResult(err error) *AuthResult

NewAuthErrorResult creates a failed result from an error

func NewAuthResult

func NewAuthResult() *AuthResult

NewAuthResult creates a successful result

func NewAuthResultWithStop

func NewAuthResultWithStop() *AuthResult

NewAuthResultWithStop creates a successful result that stops the pipeline

type RadiusError

type RadiusError interface {
	error
	// MetricsKey returns the metrics key for this error type
	MetricsKey() string
	// Stage returns the processing stage where the error occurred
	Stage() string
}

RadiusError is the base interface for all RADIUS-related errors. It provides methods for metrics tracking and error categorization.

func GetRadiusError

func GetRadiusError(err error) (RadiusError, bool)

GetRadiusError retrieves any RadiusError (AuthError or AcctError)

Jump to

Keyboard shortcuts

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