View Source Cachex.Errors (Cachex v3.6.0)

Module containing all error definitions used in the codebase.

All error messages (both shorthand and long form) can be found in this module, including the ability to convert from the short form to the long form using the long_form/1 function.

This module is provided to allow functions to return short errors, using the easy syntax of error(:short_name) to generate a tuple of { :error, :short_name } but also to allow them to be converted to a readable form as needed, rather than bloating blocks with potentially large error messages.

Link to this section Summary

Functions

Generates a tagged :error Tuple at compile time.

Returns the list of known error keys.

Converts an error identifier to it's longer form.

Link to this section Functions

@spec error(atom()) :: {:error, atom()}

Generates a tagged :error Tuple at compile time.

The provided error key must be contained in the list of known identifiers returned be known/0, otherwise this call will fail.

@spec known() :: [atom()]

Returns the list of known error keys.

@spec long_form(atom()) :: binary()

Converts an error identifier to it's longer form.

Error identifiers should be atoms and should be contained in the list of errors returned by known/0. The return type from this function will always be a binary.