2026-01-30 22:02:40 +00:00
|
|
|
// Package errors provides structured error handling for Core applications.
|
|
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// Deprecated: Use pkg/log instead. This package is maintained for backward
|
|
|
|
|
// compatibility and will be removed in a future version. All error handling
|
|
|
|
|
// functions are now available in pkg/log:
|
2026-01-30 22:02:40 +00:00
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// // Instead of:
|
|
|
|
|
// import "github.com/host-uk/core/pkg/errors"
|
|
|
|
|
// err := errors.E("op", "msg", cause)
|
2026-01-30 22:02:40 +00:00
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// // Use:
|
|
|
|
|
// import "github.com/host-uk/core/pkg/log"
|
|
|
|
|
// err := log.E("op", "msg", cause)
|
2026-01-30 22:02:40 +00:00
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// Migration guide:
|
|
|
|
|
// - errors.Error -> log.Err
|
|
|
|
|
// - errors.E -> log.E
|
|
|
|
|
// - errors.Wrap -> log.Wrap
|
|
|
|
|
// - errors.WrapCode -> log.WrapCode
|
|
|
|
|
// - errors.Code -> log.NewCode
|
|
|
|
|
// - errors.New -> log.NewError
|
|
|
|
|
// - errors.Is -> log.Is
|
|
|
|
|
// - errors.As -> log.As
|
|
|
|
|
// - errors.Join -> log.Join
|
|
|
|
|
// - errors.Op -> log.Op
|
|
|
|
|
// - errors.ErrCode -> log.ErrCode
|
|
|
|
|
// - errors.Message -> log.Message
|
|
|
|
|
// - errors.Root -> log.Root
|
refactor: remove GUI packages for CGO-free CLI
Move all Wails-dependent packages to core-gui repo:
- pkg/core, pkg/display, pkg/docs, pkg/help, pkg/ide
- pkg/runtime, pkg/webview, pkg/workspace, pkg/ws
- pkg/plugin, pkg/config, pkg/i18n, pkg/module
- pkg/crypt, pkg/io, pkg/process
Add pkg/errors with simple E() helper for error wrapping.
Update go.work to only include CLI-relevant packages.
CLI now builds with CGO_ENABLED=0 - no linker warnings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:15:01 +00:00
|
|
|
package errors
|
|
|
|
|
|
2026-01-30 22:02:40 +00:00
|
|
|
import (
|
2026-02-02 01:17:22 +00:00
|
|
|
"github.com/host-uk/core/pkg/log"
|
2026-01-30 22:02:40 +00:00
|
|
|
)
|
refactor: remove GUI packages for CGO-free CLI
Move all Wails-dependent packages to core-gui repo:
- pkg/core, pkg/display, pkg/docs, pkg/help, pkg/ide
- pkg/runtime, pkg/webview, pkg/workspace, pkg/ws
- pkg/plugin, pkg/config, pkg/i18n, pkg/module
- pkg/crypt, pkg/io, pkg/process
Add pkg/errors with simple E() helper for error wrapping.
Update go.work to only include CLI-relevant packages.
CLI now builds with CGO_ENABLED=0 - no linker warnings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:15:01 +00:00
|
|
|
|
2026-01-30 22:02:40 +00:00
|
|
|
// Error represents a structured error with operational context.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.Err instead.
|
|
|
|
|
type Error = log.Err
|
refactor: remove GUI packages for CGO-free CLI
Move all Wails-dependent packages to core-gui repo:
- pkg/core, pkg/display, pkg/docs, pkg/help, pkg/ide
- pkg/runtime, pkg/webview, pkg/workspace, pkg/ws
- pkg/plugin, pkg/config, pkg/i18n, pkg/module
- pkg/crypt, pkg/io, pkg/process
Add pkg/errors with simple E() helper for error wrapping.
Update go.work to only include CLI-relevant packages.
CLI now builds with CGO_ENABLED=0 - no linker warnings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:15:01 +00:00
|
|
|
|
|
|
|
|
// E creates a new Error with operation context.
|
2026-01-30 22:02:40 +00:00
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// Deprecated: Use log.E instead.
|
refactor: remove GUI packages for CGO-free CLI
Move all Wails-dependent packages to core-gui repo:
- pkg/core, pkg/display, pkg/docs, pkg/help, pkg/ide
- pkg/runtime, pkg/webview, pkg/workspace, pkg/ws
- pkg/plugin, pkg/config, pkg/i18n, pkg/module
- pkg/crypt, pkg/io, pkg/process
Add pkg/errors with simple E() helper for error wrapping.
Update go.work to only include CLI-relevant packages.
CLI now builds with CGO_ENABLED=0 - no linker warnings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:15:01 +00:00
|
|
|
func E(op, msg string, err error) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.E(op, msg, err)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wrap wraps an error with operation context.
|
|
|
|
|
// Returns nil if err is nil.
|
|
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// Deprecated: Use log.Wrap instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Wrap(err error, op, msg string) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.Wrap(err, op, msg)
|
refactor: remove GUI packages for CGO-free CLI
Move all Wails-dependent packages to core-gui repo:
- pkg/core, pkg/display, pkg/docs, pkg/help, pkg/ide
- pkg/runtime, pkg/webview, pkg/workspace, pkg/ws
- pkg/plugin, pkg/config, pkg/i18n, pkg/module
- pkg/crypt, pkg/io, pkg/process
Add pkg/errors with simple E() helper for error wrapping.
Update go.work to only include CLI-relevant packages.
CLI now builds with CGO_ENABLED=0 - no linker warnings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 22:02:40 +00:00
|
|
|
// WrapCode wraps an error with operation context and an error code.
|
|
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// Deprecated: Use log.WrapCode instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func WrapCode(err error, code, op, msg string) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.WrapCode(err, code, op, msg)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Code creates an error with just a code and message.
|
|
|
|
|
//
|
2026-02-02 01:17:22 +00:00
|
|
|
// Deprecated: Use log.NewCode instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Code(code, msg string) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.NewCode(code, msg)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Standard library wrappers ---
|
|
|
|
|
|
|
|
|
|
// Is reports whether any error in err's tree matches target.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.Is instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Is(err, target error) bool {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.Is(err, target)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// As finds the first error in err's tree that matches target.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.As instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func As(err error, target any) bool {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.As(err, target)
|
refactor: remove GUI packages for CGO-free CLI
Move all Wails-dependent packages to core-gui repo:
- pkg/core, pkg/display, pkg/docs, pkg/help, pkg/ide
- pkg/runtime, pkg/webview, pkg/workspace, pkg/ws
- pkg/plugin, pkg/config, pkg/i18n, pkg/module
- pkg/crypt, pkg/io, pkg/process
Add pkg/errors with simple E() helper for error wrapping.
Update go.work to only include CLI-relevant packages.
CLI now builds with CGO_ENABLED=0 - no linker warnings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 22:02:40 +00:00
|
|
|
// New returns an error with the given text.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.NewError instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func New(text string) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.NewError(text)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Join returns an error that wraps the given errors.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.Join instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Join(errs ...error) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.Join(errs...)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Helper functions ---
|
|
|
|
|
|
|
|
|
|
// Op extracts the operation from an error, or empty string if not an Error.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.Op instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Op(err error) string {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.Op(err)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ErrCode extracts the error code, or empty string if not set.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.ErrCode instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func ErrCode(err error) string {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.ErrCode(err)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Message extracts the message from an error.
|
|
|
|
|
// For Error types, returns Msg; otherwise returns err.Error().
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.Message instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Message(err error) string {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.Message(err)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Root returns the deepest error in the chain.
|
2026-02-02 01:17:22 +00:00
|
|
|
//
|
|
|
|
|
// Deprecated: Use log.Root instead.
|
2026-01-30 22:02:40 +00:00
|
|
|
func Root(err error) error {
|
2026-02-02 01:17:22 +00:00
|
|
|
return log.Root(err)
|
2026-01-30 22:02:40 +00:00
|
|
|
}
|