* query-lifecycle and started modules-interfaces * query-lifecycle first draft done * module interfaces first draft * rest and intro skeletons * rest and intro done * small edits and links * comments * revisions * cli.md comments * comments * minor edits * better flow for query lifecycle * add transactions into core * hans comments * add transactions into core * checkout master-docs files * deleted some * remove modules readme * cli.md comments * comments * module-interfaces comments * Merge PR #4857: Add Context concept doc * working * working * finish messages and queries * handler * querier * last comments! * punctuation * querier2 * consolidate intro * querier * workiiiing * refactor for new module interface * karoly review * working on baseapp doc * baseapp work * reorg * almost there * finish first draft * remove old files * finish intro * workinnn * initial commit after rebase * query-lifecycle and started modules-interfaces * query-lifecycle first draft done * module interfaces first draft * rest and intro skeletons * rest and intro done * small edits and links * comments * revisions * cli.md comments * comments * minor edits * better flow for query lifecycle * checkout master-docs files * deleted some * remove modules readme * cli.md comments * comments * module-interfaces comments * keeper * genesis * finish * Apply suggestions from code review Co-Authored-By: Hans Schoenburg <hschoenburg@users.noreply.github.com> * hans review * Update docs/core/baseapp.md Co-Authored-By: Hans Schoenburg <hschoenburg@users.noreply.github.com> * working * last comment * workin * Apply suggestions from code review * encoding and node * almost finish store * finish docs * fixes * fede comments + permalinks * hans review * add more permalinks * update docs theme version (#5239) * R4R: Docs Cleanup (#5246) * start * work * work * work * remove table of content * links intro * fix links * remove junk * cleanup * cleanup * work * finish cleanup * addback readmes * remove nft * fix links * remove dup * remove dup * remove dup * remove dup * remove dup * fix links * add subscribe events * refine rest * index page * sidebar * theme version * theme version * testing netlify * theme version * tooltip example * version * testing code embedding * reverting back * theme version * version * version * version * readme and version * cleanup * redo app anatomy * modules readme, theme version * theme version * fix modules list * theme version * new snippets * modules readme * update docs readme * modify synopsis * version * fix yaml * version * version * version * version * version * version * version * version * version * version * add hide banner * version * version * version * small fixes * modules readme, version * remove hotkeys dep, version * version * version * version * version * version * version * version * slight notice * fix links and hide * permalinks * small clean * version * resolve conflicts, add google analytics * fix merge remants * version * changelog 1/2 * Changelog: docs UI * version * remove merge conflicts * Code: Update link for Contributing to the docs to docs_readme * HTML/CSS: Update layout of homepage footer to match new layout in Figma * version * final modifs * modules, version * modules readme * link to module list from homepage * version * building modules link * version * version * fonts * version * version * fix link * fix package.json * links in explore sdk section * core concepts * version * change delimeters for frontmatter * frontmatter in comments * version * temp add tiny-cookie * fixed link issues * fixed styling issues, copy * hide frontmatter * hide frontmatter * layout fixes, padded ascii diagram * fira sans font for code * scrollbar color * move synopsis from frontmatter * move synopsis from frontmatter * code styling in synopsis fix * tutorial link * active headers * 404 fix * homepage links fix * fix link in footer * misc fixes * version * prerequisite links on mobile * version * version * Fix footer links * version * Fix permalink popup * Update version * package-lock.json * Update Questions section in the footer * Config for Algolia Docsearch * Update version * Update to the latest version of the theme * Use docs-staging as a branch for staging website * Update version * Add google analytics * Remove {hide} from Pre-Requisite Readings * Replace Riot with Discord Co-Authored-By: billy rennekamp <billy.rennekamp@gmail.com> * Fix yaml syntax error in docs * Fix formatting in keyring.md Co-authored-by: Gloria Zhao <gzhao408@berkeley.edu> Co-authored-by: gamarin <gautier@tendermint.com> Co-authored-by: Jack Zampolin <jack.zampolin@gmail.com> Co-authored-by: Hans Schoenburg <hschoenburg@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: billy rennekamp <billy.rennekamp@gmail.com>
55 lines
2.1 KiB
Markdown
55 lines
2.1 KiB
Markdown
<!--
|
|
order: 13
|
|
-->
|
|
|
|
# Errors
|
|
|
|
This document outlines the recommended usage and APIs for error handling in Cosmos SDK modules. {synopsis}
|
|
|
|
Modules are encouraged to define and register their own errors to provide better
|
|
context on failed message or handler execution. Typically, these errors should be
|
|
common or general errors which can be further wrapped to provide additional specific
|
|
execution context.
|
|
|
|
## Registration
|
|
|
|
Modules should define and register their custom errors in `x/{module}/types/errors.go`. Registration
|
|
of errors is handled via the `types/errors` package.
|
|
|
|
Example:
|
|
|
|
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.38.1/x/distribution/types/errors.go#L1-L21
|
|
|
|
Each custom module error must provide the codespace, which is typically the module name
|
|
(e.g. "distribution") and is unique per module, and a uint32 code. Together, the codespace and code
|
|
provide a globally unique SDK error. Typically, the code is monotonically increasing but does not
|
|
necessarily have to be. The only restrictions on error codes are the following:
|
|
|
|
* Must be greater than one, as a code value of one is reserved for internal errors.
|
|
* Must be unique within the module.
|
|
|
|
Note, the SDK provides a core set of *common* errors. These errors are defined in `types/errors/errors.go`.
|
|
|
|
## Wrapping
|
|
|
|
The custom module errors can be returned as their concrete type as they already fulfill the `error`
|
|
interface. However, module errors can be wrapped to provide further context and meaning to failed
|
|
execution.
|
|
|
|
Example:
|
|
|
|
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.38.1/x/distribution/keeper/querier.go#L62-L80
|
|
|
|
Regardless if an error is wrapped or not, the SDK's `errors` package provides an API to determine if
|
|
an error is of a particular kind via `Is`.
|
|
|
|
## ABCI
|
|
|
|
If a module error is registered, the SDK `errors` package allows ABCI information to be extracted
|
|
through the `ABCIInfo` API. The package also provides `ResponseCheckTx` and `ResponseDeliverTx` as
|
|
auxiliary APIs to automatically get `CheckTx` and `DeliverTx` responses from an error.
|
|
|
|
## Next {hide}
|
|
|
|
Learn about [interfaces](../interfaces/interfaces-intro.md) {hide}
|