errors

package
v1.53.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsError

func AsError(errorText string) func(loc *SrcLocation)

AsError allows you to set a SrcLocation's error text

Pass this option in when you give the error Template a src location

func AsHelp

func AsHelp(helpText string) func(loc *SrcLocation)

AsHelp allows you to set a SrcLocation's text and mark it as a helpful hint

Pass this option in when you give the error Template a src location

func AsWarning

func AsWarning(warningText string) func(loc *SrcLocation)

AsWarning allows you to set a SrcLocation's text and mark it as a warning

Pass this option in when you give the error Template a src location

Types

type LocationKind

type LocationKind uint8

LocationKind tells us what language and position markers we're using to identify the source

const (
	LocFile LocationKind = iota
	LocGoNode
	LocGoPos
	LocGoPositions
)

type LocationOption

type LocationOption func(*SrcLocation)

type LocationType

type LocationType uint8

LocationType represents if the locaton is the source of the error, a warning or a helpful hint

const (
	LocError LocationType = iota
	LocWarning
	LocHelp
)

type RangeOption

type RangeOption func(*rangeConfig)

func WithRangeSize

func WithRangeSize(size int) RangeOption

WithRangeSize sets the size of the range. The default is 100.

type SrcLocation

type SrcLocation struct {
	Kind            LocationKind
	LocType         LocationType
	Text            string
	Filepath        string
	GoNode          goAst.Node
	GoStartPos      goToken.Pos
	GoEndPos        goToken.Pos
	GoStartPosition goToken.Position
	GoEndPosition   goToken.Position
}

SrcLocation tells us where in the code base caused the error, warning or is a hint to the end user.

type Template

type Template struct {
	Code               int
	Title              string
	Summary            string
	Detail             string
	Cause              error
	Locations          []SrcLocation
	AlwaysIncludeStack bool
}

Template represents a template for a new error.

It itself is not an error, but can be used to initialize a new [errorinsrc.ErrInSrc].

func AtOptionalNode

func AtOptionalNode[T ast.Node](err Template, opt option.Option[T]) Template

AtOptionalNode returns an error at the given node if it is present. Otherwise, it returns the error unchanged.

func (Template) AtGoNode

func (t