Documentation ¶
Overview ¶
Package tracerr makes error output more informative. It adds stack trace to error and can display error with source fragments.
Check example of output here https://github.com/kadaan/tracerr
Index ¶
- Variables
- func Print(err error)
- func PrintSource(err error, nums ...int)
- func PrintSourceColor(err error, nums ...int)
- func Sprint(err error) string
- func SprintSource(err error, nums ...int) string
- func SprintSourceColor(err error, nums ...int) string
- func Unwrap(err error) error
- type Error
- type Frame
- type Tracerr
Constants ¶
This section is empty.
Variables ¶
var Default = NewTracerr(DefaultFrameCapacity, DefaultFrameSkipCount)
var DefaultFrameCapacity = 20
DefaultFrameCapacity is a default capacity for frames array. It can be changed to number of expected frames for purpose of performance optimisation.
var DefaultFrameSkipCount = 2
DefaultFrameSkipCount is a number of frames to skip when retrieving the stack frames for the error.
var DefaultLinesAfter = 2
DefaultLinesAfter is number of source lines after traced line to display.
var DefaultLinesBefore = 3
DefaultLinesBefore is number of source lines before traced line to display.
Functions ¶
func PrintSource ¶
PrintSource prints error message with stack trace and source fragments.
By default 6 lines of source code will be printed, see DefaultLinesAfter and DefaultLinesBefore.
Pass a single number to specify a total number of source lines.
Pass two numbers to specify exactly how many lines should be shown before and after traced line.
func PrintSourceColor ¶
PrintSourceColor prints error message with stack trace and source fragments, which are in color. Output rules are the same as in PrintSource.
func SprintSource ¶
SprintSource returns error output by the same rules as PrintSource.
func SprintSourceColor ¶
SprintSourceColor returns error output by the same rules as PrintSourceColor.
Types ¶
type Error ¶
Error is an error with stack trace.
func CustomError ¶
CustomError creates an error with provided frames.
type Frame ¶
type Frame struct { // Func contains a function name. Func string // Line contains a line number. Line int // Path contains a file path. Path string }
Frame is a single step in stack trace.
func StackTrace ¶
StackTrace returns stack trace of an error. It will be empty if err is not of type Error.