apperror

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Plugin errors
	TypePluginNotFound      = "omniview:plugin/not-found"
	TypePluginNotLoaded     = "omniview:plugin/not-loaded"
	TypePluginAlreadyLoaded = "omniview:plugin/already-loaded"
	TypePluginInstallFailed = "omniview:plugin/install-failed"
	TypePluginLoadFailed    = "omniview:plugin/load-failed"
	TypePluginBuildFailed   = "omniview:plugin/build-failed"

	// Settings errors
	TypeSettingsMissingConfig = "omniview:settings/missing-config"
	TypeSettingsInvalidConfig = "omniview:settings/invalid-config"

	// Resource errors
	TypeResourceNotFound     = "omniview:resource/not-found"
	TypeResourceForbidden    = "omniview:resource/forbidden"
	TypeResourceUnauthorized = "omniview:resource/unauthorized"
	TypeResourceConflict     = "omniview:resource/conflict"
	TypeResourceTimeout      = "omniview:resource/timeout"

	// Connection errors
	TypeConnectionNotFound = "omniview:connection/not-found"
	TypeConnectionFailed   = "omniview:connection/failed"

	// Session errors
	TypeSessionNotFound = "omniview:session/not-found"
	TypeSessionFailed   = "omniview:session/failed"

	// General errors
	TypeCancelled      = "omniview:cancelled"
	TypeInternal       = "omniview:internal"
	TypeValidation     = "omniview:validation"
	TypeNotImplemented = "omniview:not-implemented"
)

Error type URI constants used across Go and TypeScript.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Type   string `json:"type"` // "navigate", "retry", "open-url", "copy"
	Label  string `json:"label"`
	Target string `json:"target,omitempty"`
}

Action represents a frontend-renderable action button that can be attached to structured errors. The frontend maps each action type to a concrete UI behaviour (navigation, retry, opening a URL, or clipboard copy).

func CopyAction

func CopyAction(label, text string) Action

CopyAction creates an action that copies text to the clipboard.

func NavigateAction(label, route string) Action

NavigateAction creates an action that navigates to the given in-app route.

func OpenSettingsAction

func OpenSettingsAction(category string) Action

OpenSettingsAction creates a navigate action to the settings page with the given category.

func OpenURLAction

func OpenURLAction(label, url string) Action

OpenURLAction creates an action that opens an external URL.

func RetryAction

func RetryAction(label string) Action

RetryAction creates an action that signals the frontend to retry the operation.

type AppError

type AppError struct {
	Err         error    `json:"-"`
	Type        string   `json:"type"`
	Title       string   `json:"title"`
	Status      int      `json:"status"`
	Detail      string   `json:"detail"`
	Instance    string   `json:"instance,omitempty"`
	Suggestions []string `json:"suggestions,omitempty"`
	Actions     []Action `json:"actions,omitempty"`
}

AppError is a structured error type based on RFC 7807 Problem Details. Its Error() method returns a JSON string so the structured fields survive the Wails IPC boundary (Wails calls .Error() and sends the string to JS).

func Cancelled

func Cancelled() *AppError

Cancelled creates an error for user-cancelled operations.

func ConfigMissing

func ConfigMissing(setting, detail string) *AppError

ConfigMissing creates a 422 error for a missing configuration setting, with an auto-attached "Open Settings" action.

func ConnectionNotFound

func ConnectionNotFound(pluginID, connectionID string) *AppError

ConnectionNotFound creates a structured error for a missing connection.

func Forbidden

func Forbidden(title, detail string) *AppError

Forbidden creates a 403 error.

func FromResourceOperationError

func FromResourceOperationError(jsonStr string, pluginID string) *AppError

FromResourceOperationError translates a ResourceOperationError JSON string (from the existing plugin-sdk error type) into an AppError.

func Internal

func Internal(err error, title string) *AppError

Internal wraps an unexpected error as a 500.

func New

func New(errType string, status int, title, detail string) *AppError

New creates a new AppError with the given fields.

func NotFound

func NotFound(title, detail string) *AppError

NotFound creates a 404 error.

func NotImplemented

func NotImplemented(title, detail string) *AppError

NotImplemented creates a 501 error for features not yet implemented.

func PluginAlreadyLoaded

func PluginAlreadyLoaded(pluginID string) *AppError

PluginAlreadyLoaded creates a 409 conflict error for a plugin that is already loaded.

func PluginNotFound

func PluginNotFound(pluginID string) *AppError

PluginNotFound creates a structured error for a missing plugin.

func SessionNotFound

func SessionNotFound(sessionID string) *AppError

SessionNotFound creates a structured error for a missing session.

func Wrap

func Wrap(err error, errType string, status int, title string) *AppError

Wrap wraps an existing error, using err.Error() as the detail.

func WrapWithDetail

func WrapWithDetail(err error, errType string, status int, title, detail string) *AppError

WrapWithDetail wraps an existing error with a custom detail message.

func (*AppError) Error

func (e *AppError) Error() string

Error returns a JSON-encoded representation so the structured fields survive the Wails IPC boundary.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the underlying error for use with errors.Is / errors.As.

func (*AppError) WithActions

func (e *AppError) WithActions(actions ...Action) *AppError

WithActions appends frontend-renderable actions to the error.

func (*AppError) WithInstance

func (e *AppError) WithInstance(instance string) *AppError

WithInstance sets the instance field (specific occurrence context).

func (*AppError) WithSuggestions

func (e *AppError) WithSuggestions(suggestions ...string) *AppError

WithSuggestions appends user-facing suggestions to the error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL