Documentation
¶
Overview ¶
Package errors provides error handling utilities for OniWorks applications. In debug mode it renders a rich HTML error page (similar to Laravel's Ignition) with full stack trace, request details, and highlighted application frames. In production it returns a minimal JSON response.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns a router-compatible error handler. When debugMode is true and the error is not an HTTPError, it renders a detailed HTML page for browser requests or a verbose JSON payload for API requests. For HTTPError values (4xx / known 5xx) it always returns clean JSON.
Enabling debug mode exposes stack traces, file paths, and raw error strings; never enable it in production. Consider HandlerForEnv to wire this safely.
func HandlerForEnv ¶
HandlerForEnv returns an error handler with debug mode enabled ONLY when env names a development environment ("local", "dev", "development", "debug", case-insensitive). Any other value — including the empty string — yields a production handler that never leaks internals. Prefer this over Handler(true) so a stray config value can't turn on stack-trace disclosure in production.
func WithStack ¶
WithStack wraps err with the stack trace captured at the call site, so the debug error page can show where the error actually originated:
if err := doThing(); err != nil {
return errors.WithStack(err)
}
Returns nil when err is nil. The wrapper supports Unwrap, so errors.Is/As keep working on the underlying error.
Types ¶
type StackTracer ¶
type StackTracer interface {
StackTrace() []byte
}
StackTracer is implemented by errors that carry the stack captured where the error originated (see WithStack). The debug error page prefers that stack over the stack of the goroutine that happens to be *handling* the error, which usually just shows router internals.