perr

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package perr provides utilities for handling parse errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

func CatchBailout(recovered any) (l *List, ok bool)

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

func IsBailout(recovered any) (l *List, ok bool)

IsBailout reports whether a recovered value is a bailout panic. It reports the list that caused the bailout alongside.

func NewList

func NewList(ctx context.Context, fset *token.FileSet) *List

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) Add

func (l *List) Add(template errors.Template)

Add adds a templated error

func (*List) AddPos

func (l *List) AddPos(pos token.Pos, msg string)

Add adds an error at the given pos.

func (*List) AddStd

func (l *List) AddStd(err error)

AddStd adds an error from the stdlib packages that uses scanner.ErrorList or *scanner.Error under the hood.

func (*List) Addf

func (l *List) Addf(pos token.Pos, format string, args ...any)

Addf is equivalent to l.Add(pos, fmt.Sprintf(format, args...))

func (*List) AsError

func (l *List) AsError() error

AsError returns this list an error if there are errors in the list, otherwise it returns nil.

func (*List) Assert

func (l *List) Assert(template errors.Template)

func (*List) AssertStd

func (l *List) AssertStd(err error)

func (*List) At

func (l *List) At(i int) *errinsrc.ErrInSrc

At returns the i'th error. i must be 0 <= i < l.Len().

func (*List) Bailout

func (l *List) Bailout()

func (*List) BailoutOnErrors

func (l *List) BailoutOnErrors(fn func())

BailoutOnErrors calls fn and bailouts if fn reports any errors.

func (*List) FS

func (l *List) FS() *token.FileSet

func (*List) Fatal

func (l *List) Fatal(pos token.Pos, msg string)

func (*List) Fatalf

func (l *List) Fatalf(pos token.Pos, format string, args ...any)

func (*List) FormatErrors

func (l *List) FormatErrors() string

FormatErrors formats the errors as a newline-separated string. If there are no errors it returns "no errors".

func (*List) GoString

func (l *List) GoString() string

func (*List) Len

func (l *List) Len() int

Len returns the number of errors reported.

func (*List) MakeRelative

func (l *List) MakeRelative(root, relwd string)

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

func (r *ListAsErr) As(err any) bool

As implements the As method of the error interface.

It supports the following types:

  • **ListAsErr
  • **List

func (*ListAsErr) Error

func (r *ListAsErr) Error() string

Error returns the list of errors formatted as a single string.

func (*ListAsErr) ErrorList

func (r *ListAsErr) ErrorList() []*errinsrc.ErrInSrc

ErrorList returns the list of errors in the source that make up this error.

func (*ListAsErr) Unwrap

func (r *ListAsErr) Unwrap() []error

Unwrap returns the list of errors that make up this error.

Note: This version of Unwrap is a Go 1.20+ feature

Jump to

Keyboard shortcuts

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