errinsrc

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MPL-2.0 Imports: 19 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

func (Bailout) Error added in v1.9.3

func (b Bailout) Error() string

func (Bailout) ErrorList added in v1.9.3

func (b Bailout) ErrorList() []*ErrInSrc

func (Bailout) Unwrap added in v1.9.3

func (b Bailout) Unwrap() error

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 FromTemplate added in v1.14.5

func FromTemplate(template encerrors.Template, fileset *token.FileSet, fileReaders ...paths.FileReader) *ErrInSrc

FromTemplate returns a new ErrInSrc using the [errs.Template] as a template

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

func (*ErrInSrc) WithGoNode added in v1.16.2

func (e *ErrInSrc) WithGoNode(fileset *token.FileSet, node ast.Node, fileReaders ...paths.FileReader)

WithGoNode adds a Go AST node to the 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