irc

package
v0.0.0-...-c70ba75 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package irc provides a customized error code system extending the IRR library. It defines a `Code` type which represents an error code as an int64, and a set of methods that produce rich errors containing both formatted messages and these error codes. The package follows the best practices of error handling in Go by leveraging the abilities of the IRR library to capture stack traces, wrap errors, and provide context while allowing for the classification and handling of errors through unified error codes.

Best practices:

  • Define domain-specific error codes as constants using the `Code` type to maintain a registry of error codes for the application.
  • Use the `Code`-related methods to create errors with consistent formatting, additional context, and these predefined error codes.
  • Wrap errors when catching them to maintain the original error context, providing a clear error chain.
  • Provide stack traces only when it's necessary for debugging, to avoid overpopulating logs with unnecessary details.
  • Utilize error codes to handle errors gracefully within application logic or when communicating with clients via API responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int64

Code defines an int64 type for error codes. It extends the error interface by allowing the association of an error message with a code.

func DumpToCodeNError

func DumpToCodeNError(succ, unknown Code, err error, msgOrFmt string, args ...any) (code Code, msg string)

func (Code) Error

func (c Code) Error(formatOrMsg string, args ...interface{}) irr.IRR

Error creates an IRR error object with a formatted message and sets the error code.

func (Code) I64

func (c Code) I64() int64

I64 converts a Code to its int64 representation.

func (Code) String

func (c Code) String() string

String converts a Code to its string representation, typically for printing.

func (Code) Trace

func (c Code) Trace(formatOrMsg string, args ...interface{}) irr.IRR

Trace creates an IRR error object with stack trace information and sets the error code.

func (Code) TraceSkip

func (c Code) TraceSkip(skip int, formatOrMsg string, args ...interface{}) irr.IRR

TraceSkip creates an IRR error object with stack trace information, skipping the specified number of stack frames, and sets the error code.

func (Code) Track

func (c Code) Track(innerErr error, formatOrMsg string, args ...interface{}) irr.IRR

Track creates an IRR error object that wraps an inner error with stack trace information and sets the error code.

func (Code) TrackSkip

func (c Code) TrackSkip(skip int, innerErr error, formatOrMsg string, args ...interface{}) irr.IRR

TrackSkip creates an IRR error object that wraps an inner error with stack trace information, skipping the specified number of frames, and sets the error code.

func (Code) Wrap

func (c Code) Wrap(innerErr error, formatOrMsg string, args ...interface{}) irr.IRR

Wrap wraps an existing error object with a formatted message and sets the error code.

type ICodeGetter

type ICodeGetter irr.ICodeGetter[int64]

ICodeGetter is an interface for types that can return an error code.

type ICodeTraverse

type ICodeTraverse irr.ITraverseCoder[int64]

ICodeTraverse is an interface for traversing codes in an error chain.

Jump to

Keyboard shortcuts

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