grr

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: BSD-3-Clause Imports: 4 Imported by: 42

README

grr

Grr provides easy, context-wrapped error handling in Go

Documentation

Overview

Package grr provides easy, context-wrapped error handling in Go.

Index

Constants

View Source
const (
	// Version is the version of this package being used
	Version = "v0.0.1"
	// GitCommit is the commit just before the latest version commit
	GitCommit = "81c9012"
	// VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04')
	VersionDate = "2023-09-21 02:45"
)

Variables

View Source
var Debug = false

Debug is whether to put the program in debug mode and print the stack traces for errors.

Functions

func Errorf

func Errorf(format string, a ...any) error

Errorf returns a new error with the given format and arguments, wrapped with a stack trace via Wrap. The result guaranteed to be of type *Error. It is the grr equivalent of fmt.Errorf.

func New

func New(text string) error

New returns a new error with the given text, wrapped with a stack trace via Wrap. The result guaranteed to be of type *Error. It is the grr equivalent of errors.New.

func Stack

func Stack() []runtime.Frame

Stack returns the stack trace up to this caller as a slice of frames.

func Wrap

func Wrap(err error) error

Wrap wraps the given error into an error object with a stack trace. It returns nil if the given error is nil. If it is not nil, the result is guaranteed to be of type *Error.

Types

type Error

type Error struct {
	Base  error
	Stack []runtime.Frame
}

Error is the main type of grr and represents an error with a base error and a stack trace.

func (*Error) Error

func (e *Error) Error() string

Error returns the error as a string, wrapping the string of the base error with the stack trace.

func (*Error) String

func (e *Error) String() string

String returns the error as a string, wrapping the string of the base error with the stack trace.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying base error of the Error.

Jump to

Keyboard shortcuts

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