package diag

import "src.elv.sh/pkg/diag"

Package diag contains building blocks for formatting and processing diagnostic information.

Index

Package Files

context.go doc.go error.go multierror.go range.go show_error.go shower.go

func Complain

func Complain(w io.Writer, msg string)

Complain prints a message to w in bold and red, adding a trailing newline.

func Complainf

func Complainf(w io.Writer, format string, args ...interface{})

Complainf is like Complain, but accepts a format string and arguments.

func Errors

func Errors(errs ...error) error

Errors concatenate multiple errors into one. If all errors are nil, it returns nil. If there is one non-nil error, it is returned. Otherwise the return value is a MultiError containing all the non-nil arguments. Arguments of the type MultiError are flattened.

func ShowError

func ShowError(w io.Writer, err error)

ShowError shows an error. It uses the Show method if the error implements Shower, and uses Complain to print the error message otherwise.

type Context

type Context struct {
    Name   string
    Source string
    Ranging
    // contains filtered or unexported fields
}

Context is a range of text in a source code. It is typically used for errors that can be associated with a part of the source code, like parse errors and a traceback entry.

func NewContext

func NewContext(name, source string, r Ranger) *Context

NewContext creates a new Context.

func (*Context) Show

func (c *Context) Show(sourceIndent string) string

Show shows a SourceContext.

func (*Context) ShowCompact

func (c *Context) ShowCompact(sourceIndent string) string

ShowCompact shows a SourceContext, with no line break between the source position range description and relevant source excerpt.

type Error

type Error struct {
    Type    string
    Message string
    Context Context
}

Error represents an error with context that can be showed.

func (*Error) Error

func (e *Error) Error() string

Error returns a plain text representation of the error.

func (*Error) Range

func (e *Error) Range() Ranging

Range returns the range of the error.

func (*Error) Show

func (e *Error) Show(indent string) string

Show shows the error.

type MultiError

type MultiError struct {
    Errors []error
}

MultiError pack multiple errors into one error.

func (MultiError) Error

func (es MultiError) Error() string

type Ranger

type Ranger interface {
    // Range returns the range associated with the value.
    Range() Ranging
}

Ranger wraps the Range method.

type Ranging

type Ranging struct {
    From int
    To   int
}

Ranging represents a range [From, To) within an indexable sequence. Structs can embed Ranging to satisfy the Ranger interface.

func MixedRanging

func MixedRanging(a, b Ranger) Ranging

MixedRanging returns a Ranging from the start position of a to the end position of b.

func PointRanging

func PointRanging(p int) Ranging

PointRanging returns a zero-width Ranging at the given point.

func (Ranging) Range

func (r Ranging) Range() Ranging

Range returns the Ranging itself.

type Shower

type Shower interface {
    // Show takes an indentation string and shows.
    Show(indent string) string
}

Shower wraps the Show function.

Package diag imports 5 packages (graph) and is imported by 9 packages. Updated 1 month ago.

.
Tools for package owners.