stacktraces

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package stacktraces provides pretty-printed, coloured runtime error output for the English language interpreter.

It detects whether the terminal supports ANSI colour and renders errors with full call-stack information in a consistent, human-readable format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasColor

func HasColor() bool

HasColor reports whether stderr supports ANSI colour output.

Colour is disabled when any of the following conditions holds:

  • The NO_COLOR environment variable is set to any value, including the empty string (https://no-color.org/ – "when set, even to empty").
  • stderr is not a TTY (e.g. piped or redirected).

func Print

func Print(err error)

Print writes the formatted error to stderr.

func Render

func Render(err error) string

Render formats err as a pretty, colour-aware string.

When colour is not supported the output is plain text but still contains the full call-stack so that information is never lost.

func RenderWithColor

func RenderWithColor(err error, color bool) string

RenderWithColor formats err as a pretty string using the explicit colour flag. Pass HasColor() for normal use; pass true/false in tests or when the caller has already determined colour support.

Types

type CompileError

type CompileError interface {
	error
	CompileMessage() string
	CompileLine() int
}

CompileError is the interface satisfied by vm.TypeError and parse errors that carry source-location information. Using a local interface avoids an import cycle between this package and vm.

type CompileFileError

type CompileFileError interface {
	CompileError
	CompileFile() string
}

CompileFileError is an optional extension of CompileError implemented by errors that also know which source file they originated from (e.g. an error inside an imported .abc file).

type RuntimeError

type RuntimeError interface {
	error
	RuntimeMessage() string
	RuntimeLine() int
	RuntimeCallStack() []string
}

RuntimeError is the interface satisfied by vm.RuntimeError. Using a local interface avoids an import cycle between this package and vm.

type SyntaxError

type SyntaxError interface {
	error
	SyntaxMessage() string
	SyntaxLine() int
	SyntaxCol() int
	SyntaxHint() string
}

SyntaxError is the interface satisfied by parser.SyntaxError. It carries a user-friendly message, the source line/column, and an optional hint to guide the programmer towards a fix.

Jump to

Keyboard shortcuts

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