go: cuelang.org/go/cue/errors Index | Files

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

Package Files

errors.go

func Details Uses

func Details(err error, cfg *Config) string

Details is a convenience wrapper for Print to return the error text as a string.

func New Uses

func New(msg string) error

New is a convenience wrapper for errors.New in the core library. It does not return a CUE error.

func Path Uses

func Path(err error) []string

Path returns the path of an Error if err is of that type.

func Positions Uses

func Positions(err error) []token.Pos

Positions returns all positions returned by an error, sorted by relevance when possible and with duplicates removed.

func Print Uses

func Print(w io.Writer, err error, cfg *Config)

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.

type Config Uses

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 Uses

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 Append Uses

func Append(a, b Error) Error

Append combines two errors, flattening Lists as necessary.

func Errors Uses

func Errors(err error) []Error

Errors reports the individual errors associated with an error, which is the error itself if there is only one or, if the underlying type is List, its individual elements. If the given error is not an Error, it will be promoted to one.

func Newf Uses

func Newf(p token.Pos, format string, args ...interface{}) Error

Newf creates an Error with the associated position and message.

func Promote Uses

func Promote(err error, msg string) Error

Promote converts a regular Go error to an Error if it isn't already one.

func Sanitize Uses

func Sanitize(err Error) Error

Sanitize sorts multiple errors and removes duplicates on a best effort basis. If err represents a single or no error, it returns the error as is.

func Wrapf Uses

func Wrapf(err error, p token.Pos, format string, args ...interface{}) Error

Wrapf creates an Error with the associated position and message. The provided error is added for inspection context.

type Message Uses

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 Uses

func NewMessage(format string, args []interface{}) Message

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 Uses

func (m *Message) Error() string

func (*Message) Msg Uses

func (m *Message) Msg() (format string, args []interface{})

Msg returns a printf-style format string and its arguments for human consumption.

Package errors imports 10 packages (graph) and is imported by 18 packages. Updated 2019-12-13. Refresh now. Tools for package owners.