fmt

package
v0.0.0-...-4547e52 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: GPL-3.0, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

This file was copied and modified from https://github.com/go-errors/errors in accordance to its license (MIT).

This file was copied and modified from https://github.com/go-errors/errors in accordance to its license (MIT).

This file was copied and modified from https://github.com/go-errors/errors in accordance to its license (MIT).

Index

Constants

This section is empty.

Variables

View Source
var MaxStackDepth = 50

The maximum number of stackframes on any error.

Functions

func Fprint

func Fprint(w io.Writer, a ...any) (n int, err error)

func Fprintf

func Fprintf(w io.Writer, format string, a ...any) (n int, err error)

func Fprintln

func Fprintln(w io.Writer, a ...any) (n int, err error)

func Print

func Print(a ...any) (n int, err error)

func Printf

func Printf(format string, a ...any) (n int, err error)

func Println

func Println(a ...any) (n int, err error)

func Sprint

func Sprint(a ...any) string

func Sprintf

func Sprintf(format string, a ...any) string

func Sprintln

func Sprintln(a ...any) string

Types

type Error

type Error struct {
	Err error
	// contains filtered or unexported fields
}

Error is an error with an attached stacktrace. It can be used wherever the builtin error interface is expected.

func Errorf

func Errorf(format string, a ...interface{}) *Error

Errorf creates a new error with the given message. You can use it as a drop-in replacement for fmt.Errorf() to provide descriptive errors in return values.

func New

func New(e interface{}) *Error

New makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf("%v"). The stacktrace will point to the line of code that called New.

func ParsePanic

func ParsePanic(text string) (*Error, error)

ParsePanic allows you to get an error object from the output of a go program that panicked. This is particularly useful with https://github.com/mitchellh/panicwrap.

func Wrap

func Wrap(e interface{}, skip int) *Error

Wrap makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf("%v"). The skip parameter indicates how far up the stack to start the stacktrace. 0 is from the current call, 1 from its caller, etc.

func (*Error) Callers

func (err *Error) Callers() []uintptr

Callers satisfies the bugsnag ErrorWithCallerS() interface so that the stack can be read out.

func (*Error) Error

func (err *Error) Error() string

Error returns the underlying error's message.

func (*Error) Stack

func (err *Error) Stack() []byte

Stack returns the callstack formatted the same way that go does in runtime/debug.Stack()

func (*Error) StackFrames

func (err *Error) StackFrames() []StackFrame

StackFrames returns an array of frames containing information about the stack.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Return the wrapped error (implements api for As function).

type StackFrame

type StackFrame struct {
	// The path to the file containing this ProgramCounter
	File string
	// The LineNumber in that file
	LineNumber int
	// The Name of the function that contains this ProgramCounter
	Name string
	// The Package that contains this function
	Package string
	// The underlying ProgramCounter
	ProgramCounter uintptr
}

A StackFrame contains all necessary information about to generate a line in a callstack.

func NewStackFrame

func NewStackFrame(pc uintptr) (frame StackFrame)

NewStackFrame popoulates a stack frame object from the program counter.

func (*StackFrame) Func

func (frame *StackFrame) Func() *runtime.Func

Func returns the function that contained this frame.

func (*StackFrame) SourceLine

func (frame *StackFrame) SourceLine() (string, error)

SourceLine gets the line of code (from File and Line) of the original source if possible.

func (*StackFrame) String

func (frame *StackFrame) String() string

String returns the stackframe formatted in the same way as go does in runtime/debug.Stack()

Jump to

Keyboard shortcuts

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