Documentation
¶
Overview ¶
Package errors provides structured error handling for the Drift framework.
Index ¶
- func CaptureStack() string
- func Recover(op string)
- func RecoverWithCallback(op string, callback func(r any))
- func Report(err *DriftError)
- func ReportBoundaryError(err *BoundaryError)
- func ReportPanic(err *PanicError)
- func SetHandler(h ErrorHandler)
- type BoundaryError
- type DriftError
- type ErrorHandler
- type ErrorKind
- type LayoutIssue
- type LogHandler
- type PanicError
- type ParseError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureStack ¶
func CaptureStack() string
CaptureStack returns the current call stack as a string. It skips the first few frames to exclude the CaptureStack call itself.
func Recover ¶
func Recover(op string)
Recover is a helper for deferred panic recovery. Usage: defer errors.Recover("operation.name")
func RecoverWithCallback ¶
RecoverWithCallback is like Recover but also calls the provided callback with the panic value after reporting it.
func Report ¶
func Report(err *DriftError)
Report sends an error to the global handler. If err.Timestamp is zero, it is set to the current time.
func ReportBoundaryError ¶ added in v0.7.0
func ReportBoundaryError(err *BoundaryError)
ReportBoundaryError sends a boundary error to the global handler. This is called automatically when an [ErrorBoundary] catches a panic, or when the engine's global panic recovery captures an error. Use this to report errors to your logging/analytics infrastructure by implementing a custom ErrorHandler.
func ReportPanic ¶
func ReportPanic(err *PanicError)
ReportPanic sends a panic error to the global handler.
func SetHandler ¶
func SetHandler(h ErrorHandler)
SetHandler configures the global error handler. Pass nil to restore the default LogHandler.
Types ¶
type BoundaryError ¶ added in v0.7.0
type BoundaryError struct {
// Phase is the phase where the error occurred.
Phase string
// Widget is the type name of the widget that failed (for build errors).
Widget string
// RenderObject is the type name of the render object that failed (for layout/paint/hittest errors).
RenderObject string
// IsLayoutIssue indicates this is a developer layout mistake, not a crash.
IsLayoutIssue bool
// Recovered is the panic value (nil for regular errors).
Recovered any
// Err is the underlying error (nil for panics).
Err error
// StackTrace contains the call stack at the time of the error.
StackTrace string
// Timestamp is when the error occurred.
Timestamp time.Time
}
BoundaryError represents a failure caught by an ErrorBoundary or the global panic recovery in the engine. This is a unified error type that covers all phases.
Possible Phase values:
- "build": panic during widget Build()
- "layout": panic during RenderObject layout
- "paint": panic during RenderObject paint
- "hittest": panic during hit testing
- "frame": panic during frame processing (dispatch callbacks, animations, etc.)
- "pointer": panic during pointer/gesture event handling
func (*BoundaryError) Error ¶ added in v0.7.0
func (e *BoundaryError) Error() string
func (*BoundaryError) Unwrap ¶ added in v0.7.0
func (e *BoundaryError) Unwrap() error
type DriftError ¶
type DriftError struct {
// Op is the operation that failed (e.g., "graphics.DefaultFontManager").
Op string
// Kind categorizes the error.
Kind ErrorKind
// Err is the underlying error.
Err error
// Channel is the platform channel name, if applicable.
Channel string
// StackTrace contains the call stack at the time of the error.
StackTrace string
// Timestamp is when the error occurred.
Timestamp time.Time
}
DriftError represents a structured error in the Drift framework.
func (*DriftError) Error ¶
func (e *DriftError) Error() string
func (*DriftError) Unwrap ¶
func (e *DriftError) Unwrap() error
type ErrorHandler ¶
type ErrorHandler interface {
// HandleError is called when an error occurs.
HandleError(err *DriftError)
// HandlePanic is called when a panic is recovered.
HandlePanic(err *PanicError)
// HandleBoundaryError is called when an ErrorBoundary catches an error
// or a panic is caught by global recovery.
HandleBoundaryError(err *BoundaryError)
}
ErrorHandler receives errors reported by the Drift framework.
var ( // DefaultHandler is the global error handler. // It defaults to LogHandler with verbose=false. DefaultHandler ErrorHandler = &LogHandler{} )
type ErrorKind ¶
type ErrorKind int
ErrorKind identifies the category of an error.
const ( // KindUnknown indicates an error of unknown type. KindUnknown ErrorKind = iota // KindPlatform indicates a platform channel or native bridge error. KindPlatform // KindParsing indicates an event parsing failure. KindParsing // KindInit indicates an initialization error. KindInit // KindRender indicates a rendering error. KindRender // KindPanic indicates a recovered panic. KindPanic // KindBuild indicates a build-time widget error. KindBuild )
type LayoutIssue ¶ added in v0.23.4
type LayoutIssue struct {
Message string
}
LayoutIssue is a panic value used for constraint violations and other developer-facing layout mistakes. Recovery code detects this type and presents a calmer "layout issue" screen instead of a crash error.
func (LayoutIssue) Error ¶ added in v0.23.4
func (e LayoutIssue) Error() string
type LogHandler ¶
type LogHandler struct {
// Verbose enables detailed output including stack traces.
Verbose bool
}
LogHandler is an ErrorHandler that logs errors to stderr.
func (*LogHandler) HandleBoundaryError ¶ added in v0.7.0
func (h *LogHandler) HandleBoundaryError(err *BoundaryError)
HandleBoundaryError logs a BoundaryError to stderr.
func (*LogHandler) HandleError ¶
func (h *LogHandler) HandleError(err *DriftError)
HandleError logs a DriftError to stderr.
func (*LogHandler) HandlePanic ¶
func (h *LogHandler) HandlePanic(err *PanicError)
HandlePanic logs a PanicError to stderr.
type PanicError ¶
type PanicError struct {
// Op is the operation that panicked (e.g., "engine.HandlePointer").
Op string
// Value is the value passed to panic().
Value any
// StackTrace contains the call stack at the time of the panic.
StackTrace string
// Timestamp is when the panic occurred.
Timestamp time.Time
}
PanicError represents a recovered panic.
func (*PanicError) Error ¶
func (e *PanicError) Error() string
type ParseError ¶
type ParseError struct {
// Channel is the platform channel that received the event.
Channel string
// DataType is the expected type name.
DataType string
// Got is the actual data received.
Got any
}
ParseError represents a failure to parse event data.
func (*ParseError) Error ¶
func (e *ParseError) Error() string