cosmos-sdk/errors
dependabot[bot] f68f131285
build(deps): Bump google.golang.org/grpc from 1.74.2 to 1.75.0 in /core (#25214)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: aljo242 <alex@interchainlabs.io>
2025-08-21 19:49:47 +00:00
..
abci_test.go chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00
abci.go chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00
CHANGELOG.md chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00
doc.go chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00
errors_test.go fix: do not panic if registering the same error to global registry (#24568) 2025-05-08 16:59:45 +00:00
errors.go chore: polishing docs and comments: typo fixes for clarity (#25081) 2025-08-04 15:35:53 +00:00
go.mod build(deps): Bump google.golang.org/grpc from 1.74.2 to 1.75.0 in /core (#25214) 2025-08-21 19:49:47 +00:00
go.sum build(deps): Bump google.golang.org/grpc from 1.74.2 to 1.75.0 in /core (#25214) 2025-08-21 19:49:47 +00:00
handle.go chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00
README.md docs: lint (#24854) 2025-06-11 10:20:44 -04:00
stacktrace_test.go chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00
stacktrace.go chore: fix grammatical errors in log package comments (#25155) 2025-08-12 17:44:55 +00:00

Errors

This package provides structured error handling for Cosmos SDK apps. It supports:

  • Custom error codes and messages
  • Stack traces when wrapping errors
  • ABCI-compatible responses for Tendermint
  • Optional gRPC status codes

Usage

Registering Errors

Define root errors with a unique code and description:

var ErrInvalidInput = errors.Register("app", 1001, "invalid input")

You can wrap errors to add context:

return errors.Wrap(ErrInvalidInput, "missing field")

Getting ABCI Error Info

To convert an error to ABCI-compatible output:

codespace, code, log := errors.ABCIInfo(err, debug)

Set debug = true to include stack traces in logs.

Suppress Duplicate Error Warnings

To prevent logging when the same error is registered twice, set:

export COSMOS_SDK_SUPPRESS_DUPLICATE_ERROR_CODE_LOG=true

Useful in tests or modules that may re-register the same error.