# README
errors
This errors
package is designed based on Failure is your Domain blog:
The tricky part about errors is that they need to be different things to different consumers of them.
In any given system, we have at least 3 consumer roles — the application, the end user, & the operator.
Features
- Allows specifying
Logical Operation
that caused the failure. helpsthe operator
- Allows specifying
Machine-readable
error code. helpsthe application
- Allows specifying
Human-readable
message. helpsthe end user
- Allows specifying nested error.
- Support gRPC styles errors with Details
ErrorCode helps to categorize errors into:
- System Errors - Only recoverable after fixing system failures. e.g., disk fill, database down., certs expaired.
- Temporary Errors - Recoverable immediately after retry with exponential backoff
- Data Errors - Input validation errors which need to be reprocessed after fixing the data issues
Each feature can be added to the previous wrapped
or leaf
error, using available wrapper constructors
While using wrapped errors, you can reveal each character/trait by unwrapping like an Onion 🧅.
using Unwrap()
/ As()
/ Is()
or helpers functions GetAllDetails
, FlattenDetails
, HasAssertionFailure
, GetCategory
, GetCode
, GetOperation
etc.
Interface
type ErrorOperation interface {
error
Operation() string
}
type ErrorCoder interface {
error
Code() codes.Code
Category() categories.Category
}
TODO
- make this package generic (use
int
instead focodes.Code
?) and move it totoolkit
codes.Code
should be in consuming application- Explore implementation of kratos errors and connect errors
Reference
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
New constructors are for creating Leaf errors.
No description provided by the author
Wrapper constructors are for wrapping additional traits to previous error WithCode adds code to an existing error.
WithCodeAndOperation adds code and operation to an existing error.
WithOperation adds operation to an existing error.
# Interfaces
ErrorHinter is implemented by types that can provide Machine-readable error code.
ErrorOperation is implemented by types that can provide Logical Operation that caused the failure.