package errors
import "cuelang.org/go/cue/errors"
Package errors defines shared types for handling CUE errors.
The pivotal error type in CUE packages is the interface type Error. The information available in such errors can be most easily retrieved using the Path, Positions, and Print functions.
Index ¶
- func New(msg string) error
- func Path(err error) []string
- func Positions(err error) []token.Pos
- func Print(w io.Writer, err error, cfg *Config)
- type Config
- type Error
- func E(args ...interface{}) Error
- func Newf(p token.Pos, format string, args ...interface{}) Error
- func Wrapf(err error, p token.Pos, format string, args ...interface{}) Error
- type List
- func (p *List) Add(err Error)
- func (p *List) AddNewf(pos token.Pos, msg string, args ...interface{})
- func (p List) Err() error
- func (p List) Error() string
- func (p List) Len() int
- func (p List) Less(i, j int) bool
- func (p *List) RemoveMultiples()
- func (p *List) Reset()
- func (p List) Sort()
- func (p List) Swap(i, j int)
- type Message
Functions ¶
func New ¶
New is a convenience wrapper for errors.New in the core library. It does not return a CUE error.
func Path ¶
Path returns the path of an Error if err is of that type.
func Positions ¶
Positions returns all positions returned by an error, sorted by relevance when possible and with duplicates removed.
func Print ¶
Print is a utility function that prints a list of errors to w, one error per line, if the err parameter is an List. Otherwise it prints the err string.
Types ¶
type Config ¶
type Config struct { // Format formats the given string and arguments and writes it to w. // It is used for all printing. Format func(w io.Writer, format string, args ...interface{}) // Cwd is the current working directory. Filename positions are taken // relative to this path. Cwd string // ToSlash sets whether to use Unix paths. Mostly used for testing. ToSlash bool }
A Config defines parameters for printing.
type Error ¶
type Error interface { // Position returns the primary position of an error. If multiple positions // contribute equally, this reflects one of them. Position() token.Pos // InputPositions reports positions that contributed to an error, including // the expressions resulting in the conflict, as well as values that were // the input to this expression. InputPositions() []token.Pos // Error reports the error message without position information. Error() string // Path returns the path into the data tree where the error occurred. // This path may be nil if the error is not associated with such a location. Path() []string // Msg returns the unformatted error message and its arguments for human // consumption. Msg() (format string, args []interface{}) }
Error is the common error message.
func E ¶
func E(args ...interface{}) Error
E creates a new error. The following types correspond to the following methods:
arg type maps to Message Msg string shorthand for a format message with no arguments token.Pos Position []token.Pos Positions error Unwrap/Cause
func Newf ¶
Newf creates an Error with the associated position and message.
func Wrapf ¶
Wrapf creates an Error with the associated position and message. The provided error is added for inspection context.
type List ¶
type List []Error
List is a list of Errors. The zero value for an List is an empty List ready to use.
func (*List) Add ¶
Add adds an Error with given position and error message to an List.
func (*List) AddNewf ¶
AddNewf adds an Error with given position and error message to an List.
func (List) Err ¶
Err returns an error equivalent to this error list. If the list is empty, Err returns nil.
func (List) Error ¶
An List implements the error interface.
func (List) Len ¶
List implements the sort Interface.
func (List) Less ¶
func (*List) RemoveMultiples ¶
func (p *List) RemoveMultiples()
RemoveMultiples sorts an List and removes all but the first error per line.
func (*List) Reset ¶
func (p *List) Reset()
Reset resets an List to no errors.
func (List) Sort ¶
func (p List) Sort()
Sort sorts an List. *posError entries are sorted by position, other errors are sorted by error message, and before any *posError entry.
func (List) Swap ¶
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
A Message implements the error interface as well as Message to allow internationalized messages. A Message is typically used as an embedding in a CUE message.
func NewMessage ¶
NewMessage creates an error message for human consumption. The arguments are for later consumption, allowing the message to be localized at a later time. The passed argument list should not be modified.
func (*Message) Error ¶
func (*Message) Msg ¶
Msg returns a printf-style format string and its arguments for human consumption.
Source Files ¶
errors.go
- Version
- v0.0.4-rc1
- Published
- Jul 1, 2019
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 15 minutes ago –
Tools for package owners.