rocketmq-error
rocketmq-error is the shared error kernel for the RocketMQ Rust workspace. It
provides typed causes, stable descriptor identity, explicit protocol
projections, bounded context, and redaction-safe boundary views.
What This Crate Owns
- The opaque canonical
Error,Result<T>, andSharedErrortypes. ErrorDescriptorand the singleALL_DESCRIPTORScatalog.- Stable descriptor metadata: code, class, condition, fault attribution, component, fixed public message, severity, recovery hint, backtrace policy, exposure, four explicit boundary projections, and ordered field schemas.
ErrorContext,PublicErrorView,DiagnosticView, andCliErrorView.
The crate intentionally does not depend on transport implementations or generated protobuf bindings. Its remoting, gRPC, HTTP, and CLI projection types are dependency-light values consumed by boundary adapters.
Quick Start
use Arc;
use ;
let error = validate_transport_endpoint.expect_err;
let shared: SharedError = new;
assert_eq!;
Error is the sole canonical envelope. It is intentionally not cloneable;
SharedError is Arc<Error> and preserves the same descriptor, context, and
typed source when an error needs multiple owners. Crate-specific facades should
carry Error or SharedError without reconstructing them from display text.
Canonical Descriptors
Every canonical error selects exactly one immutable descriptor. Code that needs stable behavior reads the descriptor rather than deriving policy from a display string or caller override.
use ;
let error = new
.with_context;
let descriptor = error.descriptor;
assert_eq!;
assert_eq!;
assert_eq!;
ALL_DESCRIPTORS is the sole catalog. descriptor_by_code performs exact
lookup of canonical lowercase dotted codes. Stable behavior is selected
directly from descriptors; there is no central structural error kind or reverse
descriptor-to-kind mapping.
A descriptor explicitly owns all four projections:
RemotingSpecfor RocketMQ response codes.GrpcSpecfor payload and transport status.HttpSpecfor HTTP status.CliSpecfor process exit status.
Boundary Views and Redaction
Use PublicErrorView for approved public context fields at remoting, gRPC,
HTTP, dashboard, or other public adapters. Read protocol mappings directly
from the descriptor-owned projection. CliErrorView provides the corresponding
CLI projection.
use ;
let error = new.with_context;
let view = error.public_view.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
For Exposure::Generic, a boundary view exposes the fixed message and no
dynamic public fields. For Exposure::Public, it exposes only fields whose
descriptor schema declares ContextVisibility::Public.
Original diagnostic context remains available on the typed error and through
DiagnosticView. Secret-bearing values are never stored in ErrorContext;
only bounded, value-free presence markers are recorded. Typed source text,
locations, and backtraces are not rendered by safe public views.
use fields;
use ErrorContext;
let context = new
.with_text
.with_secret_presence;
assert_eq!;
Recovery and Severity
RecoveryHint is catalog-owned advice, not a complete retry decision.
Operation owners combine it with idempotency, progress, deadline, and retry
budget.
Current recovery hints are Never, Backoff, RefreshRoute,
RefreshLeader, SwitchBroker, RefreshCredentials, and
OperatorAction. Current severities are Debug, Info, Warn,
Error, and Critical.
use Error;
use ErrorSeverity;
use CONTROLLER_LEADERSHIP_NOT_LEADER;
let error = new;
assert_eq!;
assert_eq!;
Typed Sources
Use source-preserving constructors when a lower-level operation failed.
std::error::Error::source() retains the original typed cause; safe views
never stringify it.
use Error as _;
use ;
let error = caused_by
.with_context;
assert!;
let public = error.public_view.unwrap;
assert_eq!;
Public API Notes
- Stable integrations use descriptor codes and projections, not
Display. - Descriptor and projection construction is private; catalog constants are read-only public values.
- The crate maintains one current error model and does not provide a versioned compatibility facade.
- Component-specific adapters may expose narrow facades, but canonical identity, context, typed sources, and boundary projections remain descriptor-owned.
Tests
Run from the workspace root:
Focused catalog and association suites:
License
Licensed under Apache License, Version 2.0.
Contributing
Contributions are welcome. Read the workspace Contributing Guide before submitting changes.