Skip to content

Improve internal error types #256

@str4d

Description

@str4d

There are three kinds of errors we need to deal with:

  • Errors returned to users from CLI commands.
  • Errors returned to users via JSON-RPC.
  • Errors produced by internal components that are consumed by other internal components (usually by being converted to one of the other two kind of errors).

Currently we are using an ErrorKind enum for the first type of errors and converting to the second kind as needed:

// Fetch spending key last, to avoid a keystore decryption if unnecessary.
let seed = keystore
.decrypt_seed(derivation.seed_fingerprint())
.await
.map_err(|e| match e.kind() {
// TODO: Improve internal error types.
crate::error::ErrorKind::Generic if e.to_string() == "Wallet is locked" => {
LegacyCode::WalletUnlockNeeded.with_message(e.to_string())
}
_ => LegacyCode::Database.with_message(e.to_string()),
})?;

We should instead have comprehensive granular errors internally, and then map them to the appropriate user-facing errors at the necessary boundary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rpc-interfaceArea: RPC interfaceI-error-handlingProblems and improvements related to error handling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions