errutil

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errutil is a utility package for errors.

Index

Constants

This section is empty.

Variables

View Source
var ScopeDelimiter = "/"

ScopeDelimiter is the delimiter used in joined error scopes.

Functions

func AsPos

func AsPos(err error) (int, int)

AsPos returns the position of the error, or 0,0 if the error doesn't have a position.

Only the first position found is used. I.e. shadowed Pos errors are ignored.

func AsScope

func AsScope(err error) string

AsScope returns the error's scope, or empty string if the error isn't scoped.

func NewPos

func NewPos(err error, line, column int) error

NewPos wraps an error with a position. If added to an error that already has a position, then that inner position is shadowed by this new position, rendering it hidden/ignored.

func NewPosFromNode

func NewPosFromNode(err error, node *yaml.Node) error

NewPosFromNode is a utility function that creates a new Pos error based on the position info from a YAML node.

func Scope

func Scope(err error, paths ...string) error

Scope creates a new scoped error. The full scope path can later be retrieved from the first scope found via errors.As.

func SortByPos

func SortByPos(errs Slice)

SortByPos sorts a slice of errors by their position. Errors without a position are placed first in the list in arbitrary order.

Types

type Pos

type Pos struct {
	Err    error
	Line   int
	Column int
}

Pos is a positioned error type that holds metadata about where the error occurred (line and column).

func (Pos) Error

func (err Pos) Error() string

Error implements the error interface.

func (Pos) Is

func (err Pos) Is(target error) bool

Is implements the interface to support errors.Is.

func (Pos) Unwrap

func (err Pos) Unwrap() error

Unwrap implements the interface to support errors.Unwrap.

type Scoped

type Scoped struct {
	// contains filtered or unexported fields
}

Scoped is an error that is scoped. Each scope adds a substring to the scope, delimited by ScopeDelimiter.

func (Scoped) Error

func (err Scoped) Error() string

Error implements the error interface.

func (Scoped) Is

func (err Scoped) Is(target error) bool

Is implements the interface to support errors.Is.

func (Scoped) Scope

func (err Scoped) Scope() string

Scope returns the joined scope of this error and all inner errors.

func (Scoped) Unwrap

func (err Scoped) Unwrap() error

Unwrap implements the interface to support errors.Unwrap.

type Slice

type Slice []error

Slice is a slice of errors.

func ScopeSlice

func ScopeSlice(errs Slice, paths ...string) Slice

ScopeSlice adds paths to all the errors in the slice.

func (*Slice) Add

func (s *Slice) Add(errs ...error)

Add appends another error to this slice of errors. Nil errors are ignored.

Jump to

Keyboard shortcuts

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