errors
Package errors provides structured error handling for the Drift framework.
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
func RecoverWithCallback(op string, callback func(r any))
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 ReportBuildError
func ReportBuildError(err *BuildError)
ReportBuildError sends a build error to the global handler.
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.
type BuildError
BuildError represents a failure during widget build.
type BuildError struct {
// Widget is the type name of the widget that failed.
Widget string
// Element is the element type (StatelessElement, StatefulElement, etc.).
Element string
// 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
}
func (*BuildError) Error
func (e *BuildError) Error() string
func (*BuildError) Unwrap
func (e *BuildError) Unwrap() error
type DriftError
DriftError represents a structured error in the Drift framework.
type DriftError struct {
// Op is the operation that failed (e.g., "rendering.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
}
func (*DriftError) Error
func (e *DriftError) Error() string
func (*DriftError) Unwrap
func (e *DriftError) Unwrap() error
type ErrorHandler
ErrorHandler receives errors reported by the Drift framework.
type ErrorHandler interface {
// HandleError is called when an error occurs.
HandleError(err *DriftError)
// HandlePanic is called when a panic is recovered.
HandlePanic(err *PanicError)
// HandleBuildError is called when a widget build fails.
HandleBuildError(err *BuildError)
}
var (
// DefaultHandler is the global error handler.
// It defaults to LogHandler with verbose=false.
DefaultHandler ErrorHandler = &LogHandler{}
)
type ErrorKind
ErrorKind identifies the category of an error.
type ErrorKind int
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
)
func (ErrorKind) String
func (k ErrorKind) String() string
type LogHandler
LogHandler is an ErrorHandler that logs errors to stderr.
type LogHandler struct {
// Verbose enables detailed output including stack traces.
Verbose bool
}
func (*LogHandler) HandleBuildError
func (h *LogHandler) HandleBuildError(err *BuildError)
HandleBuildError logs a BuildError 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
PanicError represents a recovered panic.
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
}
func (*PanicError) Error
func (e *PanicError) Error() string
type ParseError
ParseError represents a failure to parse event data.
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
}
func (*ParseError) Error
func (e *ParseError) Error() string
Generated by gomarkdoc