package
0.5.2
Repository: https://github.com/xmlking/toolkit.git
Documentation: pkg.go.dev

# 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. helps the operator
  • Allows specifying Machine-readable error code. helps the application
  • Allows specifying Human-readable message. helps the end user
  • Allows specifying nested error.
  • Support gRPC styles errors with Details

ErrorCode helps to categorize errors into:

  1. System Errors - Only recoverable after fixing system failures. e.g., disk fill, database down., certs expaired.
  2. Temporary Errors - Recoverable immediately after retry with exponential backoff
  3. 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 fo codes.Code?) and move it to toolkit
  • codes.Code should be in consuming application
  • Explore implementation of kratos errors and connect errors

Reference

# Packages

No description provided by the author
No description provided by the author

# 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.