Documentation
¶
Overview ¶
Package errors provides structured, actionable error messages for Vango.
The errors package implements a comprehensive error system that:
- Shows exact source locations (file, line, column)
- Explains what went wrong in plain language
- Suggests how to fix issues with code examples
- Links to documentation for deeper understanding
Error Categories ¶
Errors are organized into categories:
- compile: Build-time errors (type mismatches, missing imports)
- runtime: Execution errors (signal read outside component, nil pointer)
- hydration: Server/client mismatch errors
- protocol: Wire protocol errors (invalid messages, connection issues)
- validation: User input errors (form validation, route parameters)
Error Codes ¶
Each error has a unique code (e.g., "E001") that maps to:
- A short message describing the error
- A detailed explanation
- A documentation URL
Usage ¶
err := errors.New("E001").
WithLocation("app/routes/index.go", 15, 12).
WithSuggestion("Allocate and read signals inside a vango.Setup() render closure")
fmt.Println(err.Format())
// Output:
// ERROR E001: Signal read outside component context
//
// app/routes/index.go:15:12
//
// 13 │ func HomePage(p vango.NoProps) vango.Component {
// 14 │ return vango.Setup(p, func(s vango.SetupCtx[vango.NoProps]) vango.RenderFn {
// 15 │ count := setup.Signal(&s, 0)
// → 16 │ return func() *vango.VNode { return Div(Textf("%d", count.Get())) }
// │ ^
// 17 │ })
// 18 │ }
//
// Hint: Allocate signals in Setup and read them in the render closure
//
// Learn more: https://vango.dev/docs/errors/E001
Index ¶
- func DisableColors()
- func EnableColors()
- func GetAllCodes() []string
- func PrintError(err error)
- func Register(code string, template ErrorTemplate)
- type Category
- type ErrorTemplate
- type Location
- type VangoError
- func (e *VangoError) Error() string
- func (e *VangoError) Format() string
- func (e *VangoError) FormatCompact() string
- func (e *VangoError) FormatJSON() string
- func (e *VangoError) Unwrap() error
- func (e *VangoError) WithContext(lines []string) *VangoError
- func (e *VangoError) WithDetail(d string) *VangoError
- func (e *VangoError) WithExample(ex string) *VangoError
- func (e *VangoError) WithLocation(file string, line, column int) *VangoError
- func (e *VangoError) WithLocationFromError(err error) *VangoError
- func (e *VangoError) WithSuggestion(s string) *VangoError
- func (e *VangoError) Wrap(err error) *VangoError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(code string, template ErrorTemplate)
Register adds a new error template to the registry.
Types ¶
type ErrorTemplate ¶
ErrorTemplate defines a registered error type.
func GetTemplate ¶
func GetTemplate(code string) (ErrorTemplate, bool)
GetTemplate returns the template for an error code.
type VangoError ¶
type VangoError struct {
// Code is a unique error identifier (e.g., "E001").
Code string
// Category is the error type (compile, runtime, etc.).
Category Category
// Message is a short description of the error.
Message string
// Detail is a longer explanation of the error.
Detail string
// Location is the source code location where the error occurred.
Location *Location
// Context contains surrounding source code lines.
Context []string
// Suggestion is a hint on how to fix the error.
Suggestion string
// Example is code showing the correct approach.
Example string
// DocURL is a link to documentation about this error.
DocURL string
// Wrapped is the underlying error, if any.
Wrapped error
}
VangoError is a structured error with source location, suggestions, and documentation.
func FromError ¶
func FromError(err error, code string) *VangoError
FromError wraps a standard error in a VangoError.
func Newf ¶
func Newf(category Category, format string, args ...any) *VangoError
Newf creates a new VangoError with a formatted message (no code).
func (*VangoError) Error ¶
func (e *VangoError) Error() string
Error implements the error interface.
func (*VangoError) Format ¶
func (e *VangoError) Format() string
Format returns a beautifully formatted error message for terminal display.
func (*VangoError) FormatCompact ¶
func (e *VangoError) FormatCompact() string
FormatCompact returns a compact single-line error format.
func (*VangoError) FormatJSON ¶
func (e *VangoError) FormatJSON() string
FormatJSON returns the error as a JSON object.
func (*VangoError) Unwrap ¶
func (e *VangoError) Unwrap() error
Unwrap returns the wrapped error for errors.Is/As support.
func (*VangoError) WithContext ¶
func (e *VangoError) WithContext(lines []string) *VangoError
WithContext adds custom context lines to the error.
func (*VangoError) WithDetail ¶
func (e *VangoError) WithDetail(d string) *VangoError
WithDetail adds a detailed explanation to the error.
func (*VangoError) WithExample ¶
func (e *VangoError) WithExample(ex string) *VangoError
WithExample adds a code example to the error.
func (*VangoError) WithLocation ¶
func (e *VangoError) WithLocation(file string, line, column int) *VangoError
WithLocation adds source location to the error.
func (*VangoError) WithLocationFromError ¶
func (e *VangoError) WithLocationFromError(err error) *VangoError
WithLocationFromError extracts location from a Go compiler error.
func (*VangoError) WithSuggestion ¶
func (e *VangoError) WithSuggestion(s string) *VangoError
WithSuggestion adds a fix suggestion to the error.
func (*VangoError) Wrap ¶
func (e *VangoError) Wrap(err error) *VangoError
Wrap wraps another error.