errinsrc

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IncludeStackByDefault = false

IncludeStackByDefault is whether to include the stack by default on all errors. This is exported to allow Encore's CI platform to set this to true for CI/CD builds.

View Source
var TerminalWidth = 100

TerminalWidth is the width of the terminal in columns that we're rendering to.

We default to 100 characters, but the CLI overrides this when it renders errors. When using the value, note it might be very small (e.g. 5) if the user has shrunk their terminal window super small. Thus any code which uses this or creates new widths off it should cope with <= 0 values.

Functions

func AddHintFromGo

func AddHintFromGo(err error, fileset *token.FileSet, node ast.Node, hint string)

func ColoursInErrors

func ColoursInErrors(enabled bool)

func ExtractFromPanic

func ExtractFromPanic(recovered any) error

ExtractFromPanic returns the first ErrInSrc or ErrorList found in the recovered value.

If no value is recovered, then nil is returned.

func Panic

func Panic(list ErrorList)

Types

type Bailout

type Bailout struct {
	List ErrorList
}

Bailout is a panic value that can be used to

type CharacterSet

type CharacterSet struct {
	HorizontalBar rune
	VerticalBar   rune
	CrossBar      rune
	VerticalBreak rune
	VerticalGap   rune
	UpArrow       rune
	RightArrow    rune
	LeftTop       rune
	MiddleTop     rune
	RightTop      rune
	LeftBottom    rune
	RightBottom   rune
	MiddleBottom  rune
	LeftBracket   rune
	RightBracket  rune
	LeftCross     rune
	RightCross    rune
	UnderBar      rune
	Underline     rune
}

type ErrInSrc

type ErrInSrc struct {
	// The parameters of the error
	// This is an internal data type to force the
	// creation of these inside `srcerrors`
	Params ErrParams `json:"params"`

	// The Stack trace of where the error was created within the Encore codebase
	// this will be empty if the error was created in a production build of Encore.
	// To populate this, build Encore with the tag `dev_build`.
	Stack []*StackFrame `json:"stack,omitempty"`
}

ErrInSrc represents an error which occurred due to the source code of the application being run through Encore.

It supports the concept of one of more locations within the users source code which caused the error. The locations will be rendered in the final output.

Construct these using helper functions in the `srcerrors` package as we can use that as a central repository error types

func New

func New(params ErrParams, alwaysIncludeStack bool) *ErrInSrc

New returns a new ErrInSrc with a Stack trace attached

func (*ErrInSrc) As

func (e *ErrInSrc) As(target any) bool

func (*ErrInSrc) Bailout

func (e *ErrInSrc) Bailout()

Bailout is a helper function which will abort the current process and report the error

func (*ErrInSrc) Error

func (e *ErrInSrc) Error() string

func (*ErrInSrc) Is

func (e *ErrInSrc) Is(target error) bool

func (*ErrInSrc) OnSameLine

func (e *ErrInSrc) OnSameLine(other *ErrInSrc) bool

func (*ErrInSrc) StackTrace

func (e *ErrInSrc) StackTrace() errors.StackTrace

StackTrace implements the StackTraceProvider interface for some libraries including ZeroLog, xerrors and Sentry

func (*ErrInSrc) Title

func (e *ErrInSrc) Title() string

func (*ErrInSrc) Unwrap

func (e *ErrInSrc) Unwrap() error

type ErrorList

type ErrorList interface {
	Error() string
	ErrorList() []*ErrInSrc
}

type List

type List []*ErrInSrc

List is a list of ErrInSrc objects.

func (List) Error

func (l List) Error() string

func (List) ErrorList

func (l List) ErrorList() []*ErrInSrc

func (List) Len

func (l List) Len() int

func (List) Less

func (l List) Less(i, j int) bool

func (List) Swap

func (l List) Swap(i, j int)

type StackFrame

type StackFrame struct {
	ProgramCounter uintptr `json:"pc"`
	File           string  `json:"file"`
	Package        string  `json:"pkg"`
	Function       string  `json:"fun"`
	Line           int     `json:"line"`
}

StackFrame represents a single frame in a Stack trace

func GetStack

func GetStack() []*StackFrame

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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