liberrors

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: ISC Imports: 5 Imported by: 0

README

Errors Library

Detailed, pretty-printed colorful errors for Go.

Check out the test/ directory for examples.

────────────────────────────────
 [!] Internal Error
    in nested_file.txt:0:2
    └─ from /tmp/some/path/to/a/file.txt:6:9

    5 |  Hello World
    6 |  testing <——

 >>> This is an example error body

Documentation

Overview

Detailed, pretty-printed colorful errors for Go

Index

Constants

View Source
const (
	ERR_INTERNAL = "Internal Error"
	ERR_ASSERT   = "Assertion Error"
	ERR_IO       = "I/O Error"
	ERR_READ     = "Reading Error"
	ERR_WRITE    = "Writing Error"
	ERR_SYNTAX   = "Syntax Error"
	ERR_FORMAT   = "Formatting Error"
	ERR_VALIDATE = "Validation Error"
	ERR_EXECUTE  = "Execution Error"
	ERR_CONVERT  = "Conversion Error"
)

Suggested values for DetailedError.Label

Variables

This section is empty.

Functions

func NewIO

func NewIO(err error, path string) error

Constructor for the most common error

func Print added in v1.1.0

func Print(err error, writer io.Writer)

Prints DetailedError{} or generic error to writer

Example usage:

libparsex.Print(err, os.Stderr)

Types

type Buffer

type Buffer struct {
	FirstLine   uint
	Buffer      string
	Highlighted string
}

func (Buffer) IsEmpty

func (buffer Buffer) IsEmpty() bool

func (Buffer) Print

func (buffer Buffer) Print(writer io.Writer)

type Context

type Context interface {
	Print(io.Writer)
}

type DetailedError

type DetailedError struct {
	Label   string
	Context Context
	Details string
}

An improved pretty-printed detailed error with context

func (*DetailedError) Error

func (err *DetailedError) Error() string

func (*DetailedError) Print

func (err *DetailedError) Print(writer io.Writer)

type DirContext

type DirContext struct {
	Path string
}

func NewDirContext added in v1.0.2

func NewDirContext(path string) DirContext

func (DirContext) Print

func (context DirContext) Print(writer io.Writer)

type FileContext

type FileContext struct {
	Trace  []TraceItem
	Buffer Buffer
}

func (FileContext) Print

func (context FileContext) Print(writer io.Writer)

type ProgramContext added in v1.1.0

type ProgramContext struct {
	Binary string
	Args   []string
	Stderr string
}

func NewProgramContext added in v1.1.0

func NewProgramContext(cmd *exec.Cmd, stderr string) ProgramContext

func (ProgramContext) Print added in v1.1.0

func (context ProgramContext) Print(writer io.Writer)

type TraceItem

type TraceItem struct {
	Name string
	// Use negative values to hide it from the output
	Col, Row int
}

func (TraceItem) PrintNested

func (item TraceItem) PrintNested(writer io.Writer)

func (TraceItem) PrintRoot

func (item TraceItem) PrintRoot(writer io.Writer)

Jump to

Keyboard shortcuts

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