actionerror

package
v0.0.0-...-3b6605c Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package actionerror defines the types and functions for structured handling of action errors within a Darlean cluster.

Index

Constants

View Source
const ERROR_KIND_APPLICATION = Kind("application")
View Source
const ERROR_KIND_FRAMEWORK = Kind("framework")

Variables

This section is empty.

Functions

func FormatTemplate

func FormatTemplate(template string, parameters map[string]any) string

Formats a template string by replacing placeholders with the specified parameters.

Placeholders must be of the form `[Name]`, where Name should be one of the keys of the parameters.

Types

type Error

type Error struct {
	Code       string         `json:"code"`
	Message    string         `json:"message"`
	Template   string         `json:"template"`
	Kind       Kind           `json:"kind"`
	Parameters map[string]any `json:"parameters"`
	Nested     []*Error       `json:"nested"`
	Stack      string         `json:"stack"`
}

Error represents an error that occurred while invoking an action.

Action errors can either be application errors (that occurred in application logic) or framework errors (that occurred within Darlean, like for network errors).

Action errors are serializable and can passed to and understood by remote actors, even in different languages.

func FromError

func FromError(e error) *Error

Returns a new application action error for the specified error.

func New

func New(options Options) *Error

Returns a new application action error for the specified options. Application code is encouraged to use this mechanism instead of regular errors, because it provides a consistent way of propagating errors throughout the Darlean cluster.

func NewActionError

func NewActionError(options Options, kind Kind) *Error

For internal use. Use New or FromError instead.

func (Error) Error

func (error Error) Error() string

Satisfies the error type.

type Kind

type Kind string

type Options

type Options struct {
	Code       string
	Template   string
	Parameters map[string]any
	Nested     []*Error
	Stack      string
}

Options can be used to create a new [base.ActionError] via [base.NewFrameworkError] or [base.NewApplicationError].

Jump to

Keyboard shortcuts

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