Skip to content

A go library that wraps existing errors with callstack information.

Notifications You must be signed in to change notification settings

albert-wang/tracederror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Tracederror

A simple error wrapper to add caller information.

Usage

Wrap errors upon return to add caller information. Instead of

	err := somethingThatCanFail(arguments)
	return err

Do

	err := somethingThatCanFail(arguments)
	return tracederror.New(err)

Since tracederror.New is idempotent, calls to tracederror.New can be inserted anywhere there is an error without extra wrapping:

func odd(a int) error{
	if a%2 == 0 {
		return tracederror.New(fmt.Errorf("Input was not odd!"))
	}

	return nil
}

func complicated(a int) error {
	err := odd(a)

	// This works even if err is nil or already a traced error.
	// If err is nil, then tracederror.New will also return nil, so no changes need to be made
	// to error handling code.
	return tracederror.New(err)
}

About

A go library that wraps existing errors with callstack information.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages