Documentation ¶
Overview ¶
Package perr provides utilities for handling parse errors.
Index ¶
- func CatchBailoutAndPanic(currentErr error, recovered any) (err error, caught bool)
- type List
- func (l *List) Add(template errors.Template)
- func (l *List) AddPos(pos token.Pos, msg string)
- func (l *List) AddStd(err error)
- func (l *List) AddStdNode(err error, node ast.Node)
- func (l *List) Addf(pos token.Pos, format string, args ...any)
- func (l *List) AsError() error
- func (l *List) Assert(template errors.Template)
- func (l *List) AssertStd(err error)
- func (l *List) At(i int) *errinsrc.ErrInSrc
- func (l *List) Bailout()
- func (l *List) BailoutOnErrors(fn func())
- func (l *List) FS() *token.FileSet
- func (l *List) Fatal(pos token.Pos, msg string)
- func (l *List) Fatalf(pos token.Pos, format string, args ...any)
- func (l *List) FormatErrors() string
- func (l *List) GoString() string
- func (l *List) Len() int
- func (l *List) MakeRelative(root, relwd string)
- func (l *List) SendToStream(stream interface{ ... }) error
- type ListAsErr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CatchBailoutAndPanic ¶ added in v1.17.0
CatchBailoutAndPanic is like CatchBailout but also catches other panics. In both types of panics it converts the result to an error.
If there is no panic it returns the error provided in the first argument back to the caller. That way, it can usually be used like so (inside a deferred function):
err, _ = perr.CatchBailoutAndPanic(err, recover())
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of errors. The same instance is shared between different components.
func CatchBailout ¶
CatchBailout catches a bailout panic and reports whether there was one. If true it also returns the error list that caused the bailout. Intended usage is:
if l, ok := perr.CatchBailout(recover()); ok { // handle bailout }
func IsBailout ¶
IsBailout reports whether a recovered value is a bailout panic. It reports the list that caused the bailout alongside.
func NewList ¶
NewList constructs a new list.
It takes a ctx to add an error on context cancellation since code often uses ctx cancellation to cause a bailout.
func (*List) AddStd ¶
AddStd adds an error from the stdlib packages that uses scanner.ErrorList or *scanner.Error under the hood.
func (*List) AsError ¶
AsError returns this list an error if there are errors in the list, otherwise it returns nil.
func (*List) BailoutOnErrors ¶
func (l *List) BailoutOnErrors(fn func())
BailoutOnErrors calls fn and bailouts if fn reports any errors.
func (*List) FormatErrors ¶
FormatErrors formats the errors as a newline-separated string. If there are no errors it returns "no errors".
func (*List) MakeRelative ¶
MakeRelative rewrites the errors by making filenames within the app root relative to the relwd (which must be a relative path within the root).
func (*List) SendToStream ¶
func (l *List) SendToStream(stream interface { Send(*daemonpb.CommandMessage) error }) error
SendToStream sends a GRPC command with this full errlist
If l is nil or empty, it sends a nil command allowing the client to know that there are no longer an error present
type ListAsErr ¶
type ListAsErr struct {
// contains filtered or unexported fields
}
ListAsErr is a wrapper around a List that implements the error interface allowing us to return a List as an error from functions that parse or compile an application.
We've not implemented Error on List directly because we want to avoid accidentally returning a List as an error, and want to be explicit about it.
func (*ListAsErr) As ¶
As implements the As method of the error interface.
It supports the following types:
- **ListAsErr
- **List