errors

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorRed    = "\033[31m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
	ColorCyan   = "\033[36m"
	ColorGray   = "\033[90m"
	ColorBold   = "\033[1m"
)

ANSI color codes for enhanced error formatting

View Source
const (
	// Syntax Error Codes (PS1xxx)
	PS1001 = "PS1001" // Unexpected token
	PS1002 = "PS1002" // Missing token
	PS1003 = "PS1003" // Invalid syntax

	// Type Error Codes (PS2xxx)
	PS2001 = "PS2001" // Type assignment error
	PS2002 = "PS2002" // Property does not exist
	PS2003 = "PS2003" // Function argument type mismatch
	PS2004 = "PS2004" // Generic constraint violation
	PS2005 = "PS2005" // Type not assignable

	// Compile Error Codes (PS3xxx)
	PS3001 = "PS3001" // Compilation failed
	PS3002 = "PS3002" // Bytecode generation error

	// Runtime Error Codes (PS4xxx)
	PS4001 = "PS4001" // Runtime exception
	PS4002 = "PS4002" // Reference error
)

Error codes for different types of errors (TypeScript-style)

Variables

This section is empty.

Functions

func DisplayErrors

func DisplayErrors(errors []PaseratiError, fallbackSource ...string)

DisplayErrors prints a list of Paserati errors in TypeScript-style format with enhanced visual presentation

Types

type CompileError

type CompileError struct {
	Position
	Msg       string
	ErrorCode string // Error code (e.g., PS3001)
	Cause     error  // Underlying cause, if any
}

CompileError represents an error during bytecode compilation.

func NewCompileError

func NewCompileError(pos Position, msg string, code ...string) *CompileError

NewCompileError creates a new compile error with optional error code

func (*CompileError) CausedBy

func (e *CompileError) CausedBy(cause error) *CompileError

func (*CompileError) Code

func (e *CompileError) Code() string

func (*CompileError) Error

func (e *CompileError) Error() string

func (*CompileError) Kind

func (e *CompileError) Kind() string

func (*CompileError) Message

func (e *CompileError) Message() string

func (*CompileError) Pos

func (e *CompileError) Pos() Position

func (*CompileError) Unwrap

func (e *CompileError) Unwrap() error

func (*CompileError) WithCode

func (e *CompileError) WithCode(code string) *CompileError

type PaseratiError

type PaseratiError interface {
	error // Embed the standard error interface
	Pos() Position
	Kind() string // e.g., "Syntax", "Type", "Compile", "Runtime"
	Code() string // Error code (e.g., "PS2001")
	// Message returns the specific error message without position info.
	// This might be useful if the caller wants to format the error differently.
	Message() string
	Unwrap() error // For error wrapping support (errors.Is/As)
}

PaseratiError is the interface implemented by all Paserati errors.

type Position

type Position struct {
	Line     int                // 1-based line number
	Column   int                // 1-based column number (rune index within the line)
	StartPos int                // 0-based byte offset of the start of the token/error span
	EndPos   int                // 0-based byte offset of the end of the token/error span (exclusive)
	Source   *source.SourceFile // Reference to the source file
}

Position represents a specific location in the source code. It includes line and column numbers (1-based) for human-readability, and byte offsets (0-based) for potential use in tooling (like LSP).

type RuntimeError

type RuntimeError struct {
	Position
	Msg          string
	ErrorCode    string // Error code (e.g., PS4001)
	Cause        error  // Underlying cause, if any
	FunctionName string // Name of the function where the error occurred (empty for script level)
	FileName     string // Name of the source file (if available)
}

RuntimeError represents an error during program execution in the VM.

func NewRuntimeError

func NewRuntimeError(pos Position, msg string, code ...string) *RuntimeError

NewRuntimeError creates a new runtime error with optional error code

func (*RuntimeError) CausedBy

func (e *RuntimeError) CausedBy(cause error) *RuntimeError

func (*RuntimeError) Code

func (e *RuntimeError) Code() string

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

func (*RuntimeError) Kind

func (e *RuntimeError) Kind() string

func (*RuntimeError) Message

func (e *RuntimeError) Message() string

func (*RuntimeError) Pos

func (e *RuntimeError) Pos() Position

func (*RuntimeError) Unwrap

func (e *RuntimeError) Unwrap() error

func (*RuntimeError) WithCode

func (e *RuntimeError) WithCode(code string) *RuntimeError

type SyntaxError

type SyntaxError struct {
	Position
	Msg       string
	ErrorCode string // Error code (e.g., PS1001)
	Cause     error  // Underlying cause, if any
}

SyntaxError represents an error during lexing or parsing.

func NewMissingTokenError

func NewMissingTokenError(pos Position, expected string) *SyntaxError

NewMissingTokenError creates a missing token error (PS1002)

func NewSyntaxError

func NewSyntaxError(pos Position, msg string, code ...string) *SyntaxError

NewSyntaxError creates a new syntax error with optional error code

func NewUnexpectedTokenError

func NewUnexpectedTokenError(pos Position, token string) *SyntaxError

NewUnexpectedTokenError creates an unexpected token error (PS1001)

func (*SyntaxError) CausedBy

func (e *SyntaxError) CausedBy(cause error) *SyntaxError

func (*SyntaxError) Code

func (e *SyntaxError) Code() string

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

func (*SyntaxError) Kind

func (e *SyntaxError) Kind() string

func (*SyntaxError) Message

func (e *SyntaxError) Message() string

func (*SyntaxError) Pos

func (e *SyntaxError) Pos() Position

func (*SyntaxError) Unwrap

func (e *SyntaxError) Unwrap() error

func (*SyntaxError) WithCode

func (e *SyntaxError) WithCode(code string) *SyntaxError

type TypeError

type TypeError struct {
	Position
	Msg       string
	ErrorCode string // Error code (e.g., PS2001)
	Cause     error  // Underlying cause, if any
}

TypeError represents an error during static type checking.

func NewArgumentTypeError

func NewArgumentTypeError(pos Position, argNum int, expectedType, actualType string) *TypeError

NewArgumentTypeError creates a function argument type mismatch error (PS2003)

func NewGenericConstraintError

func NewGenericConstraintError(pos Position, argType, constraintType, paramName string) *TypeError

NewGenericConstraintError creates a generic constraint violation error (PS2004)

func NewPropertyNotExistError

func NewPropertyNotExistError(pos Position, property, objectType string) *TypeError

NewPropertyNotExistError creates a property does not exist error (PS2002)

func NewTypeAssignmentError

func NewTypeAssignmentError(pos Position, fromType, toType string) *TypeError

NewTypeAssignmentError creates a type assignment error (PS2001)

func NewTypeError

func NewTypeError(pos Position, msg string, code ...string) *TypeError

NewTypeError creates a new type error with optional error code

func (*TypeError) CausedBy

func (e *TypeError) CausedBy(cause error) *TypeError

func (*TypeError) Code

func (e *TypeError) Code() string

func (*TypeError) Error

func (e *TypeError) Error() string

func (*TypeError) Kind

func (e *TypeError) Kind() string

func (*TypeError) Message

func (e *TypeError) Message() string

func (*TypeError) Pos

func (e *TypeError) Pos() Position

func (*TypeError) Unwrap

func (e *TypeError) Unwrap() error

func (*TypeError) WithCode

func (e *TypeError) WithCode(code string) *TypeError

Jump to

Keyboard shortcuts

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