errors

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MPL-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code interface {
	ErrorCode() int32
}

Code is an interface that allows a service embed an integer value into an error.

type Error

type Error interface {
	// WithCode sets a custom error code to be added inside the error.
	WithCode(code Code) Error

	// WithAttributes adds a set o custom log attributes to be inserted into
	// the log message.
	WithAttributes(attrs ...logger.Attribute) Error

	// Submit wraps the service error into a proper error type allowing the
	// service to return it.
	Submit(ctx context.Context) error

	// Kind returns the kind of error represented by the error.
	Kind() string
}

Error is the proper error that a service can return by its handlers. When submitted, it writes a log message describing what happened, and it gives the error using the language error type.

type ErrorAPI

type ErrorAPI interface {
	// RPC should be used when an error was received from an RPC call.
	RPC(err error, destination string) Error

	// InvalidArgument should be used when invalid arguments were received
	// inside a service handler.
	InvalidArgument(err error) Error

	// FailedPrecondition should be used when a specific condition is not met.
	FailedPrecondition(message string) Error

	// NotFound should be used when a resource was not found.
	NotFound() Error

	// Internal should be used when an unexpected behavior (or error) occurred
	// internally.
	Internal(err error) Error

	// PermissionDenied should be used when a client does not have access to
	// a specific resource.
	PermissionDenied() Error

	// Custom should be used by a service when none of the previous APIs are
	// able to handle the error that occurred. It will be forward as an internal
	// error.
	Custom(msg string) Error
}

ErrorAPI is an API that a service must use to wrap its errors into a proper framework error.

Jump to

Keyboard shortcuts

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