errors

package
v0.0.0-...-5cf1d12 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

This module implements functions which manipulate errors and provide stack trace information.

NOTE: This package intentionally mirrors the standard "errors" module. All dropbox code should use this.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMessage

func GetMessage(err interface{}) string

This returns the error string without stack trace information.

func IsError

func IsError(err, errConst error) bool

Perform a deep check, unwrapping errors as much as possilbe and comparing the string version of the error.

func RootError

func RootError(ierr error) (nerr error)

Keep peeling away layers or context until a primitive error is revealed.

Types

type DropboxError

type DropboxError interface {
	// This returns the error message without the stack trace.
	GetMessage() string

	// This returns the wrapped error.  This returns nil if this does not wrap
	// another error.
	GetInner() error

	// Implements the built-in error interface.
	Error() string

	// Returns stack addresses as a string that can be supplied to
	// a helper tool to get the actual stack trace. This function doesn't result
	// in resolving full stack frames thus is a lot more efficient.
	StackAddrs() string

	// Returns stack frames.
	StackFrames() []StackFrame

	// Returns string representation of stack frames.
	// Stack frame formatting looks generally something like this:
	// dropbox/rpc.(*clientV4).Do
	//   /srv/server/go/src/dropbox/rpc/client.go:87 +0xbf9
	// dropbox/exclog.Report
	//   /srv/server/go/src/dropbox/exclog/client.go:129 +0x9e5
	// main.main
	//   /home/cdo/tmp/report_exception.go:13 +0x84
	// It is discouraged to parse stack frames using string parsing since it can change at any time.
	// Use StackFrames() function instead to get actual stack frame metadata.
	GetStack() string
}

This interface exposes additional information about the error.

func New

func New(msg string) DropboxError

This returns a new baseError initialized with the given message and the current stack trace.

func Newf

func Newf(format string, args ...interface{}) DropboxError

Same as New, but with fmt.Printf-style parameters.

func Wrap

func Wrap(err error, msg string) DropboxError

Wraps another error in a new baseError.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) DropboxError

Same as Wrap, but with fmt.Printf-style parameters.

type StackFrame

type StackFrame struct {
	PC         uintptr
	Func       *runtime.Func
	FuncName   string
	File       string
	LineNumber int
}

Represents a single stack frame.

Jump to

Keyboard shortcuts

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