diag

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 added in v0.15.0

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 added in v0.14.0

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.

Types

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 added in v0.14.0

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

Show shows a SourceContext.

func (*Context) ShowCompact added in v0.14.0

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 added in v0.14.0

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

Show shows the error.

type MultiError added in v0.15.0

type MultiError struct {
	Errors []error
}

MultiError pack multiple errors into one error.

func (MultiError) Error added in v0.15.0

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 added in v0.14.0

func MixedRanging(a, b Ranger) Ranging

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

func PointRanging added in v0.14.0

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 added in v0.14.0

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

Shower wraps the Show function.

Jump to

Keyboard shortcuts

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