godropbox: github.com/dropbox/godropbox/errors Index | Files

package errors

import "github.com/dropbox/godropbox/errors"

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

Package Files

errors.go

func FindWrappedError Uses

func FindWrappedError(
    topErr error,
    classifier func(curErr, topErr error) error,
) (error, bool)

Performs a deep check of wrapped errors to find one which is selected by the given classifier func. The classifer is called on all non-nil errors found, starting with topErr, then on each inner wrapped error in turn until it returns non-nil which ends the scan. If the classifier ever returns a non-nil error, it will be returned from this function along with `true` to indicate something was found. Otherwise this function will return `topErr, false`.

func GetMessage Uses

func GetMessage(err interface{}) string

This returns the error string without stack trace information.

func IsError Uses

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 Uses

func RootError(ierr error) (nerr error)

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

type DropboxError Uses

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

    // This returns the wrapped error or nil if this error does not wrap another error per the
    // Go 2 error introspection proposal:
    // https://go.googlesource.com/proposal/+/master/design/29934-error-values.md
    Unwrap() 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() []runtime.Frame

    // Returns string representation of stack frames.
    // Stack frame formatting looks generally something like this:
    // dropbox/legacy_rpc.(*clientV4).Do
    //   /srv/server/go/src/dropbox/legacy_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 Uses

func New(msg string) DropboxError

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

func Newf Uses

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

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

func RootDropboxError Uses

func RootDropboxError(dbxErr DropboxError) DropboxError

Return the lowest-level DropboxError. This can be used when reporting the stack of the original exception to try and get the most relevant stack instead of the highest level stack.

func Wrap Uses

func Wrap(err error, msg string) DropboxError

Wraps another error in a new baseError.

func Wrapf Uses

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

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

Package errors imports 5 packages (graph) and is imported by 524 packages. Updated 2020-02-28. Refresh now. Tools for package owners.