Skip to content

Extend string based FibreError with more granular errors #994

Description

@citizen-stig

Currently there are several error variants in FibreClient crate, which are just wrapped string, for example:

#[error("invalid blob ID: {0}")]
InvalidBlobId(String),
/// Invalid or malformed data encountered during processing.
#[error("invalid data: {0}")]
InvalidData(String),

#[error("invalid validator signature from {validator}: {reason}")]
InvalidValidatorSignature {

#[error("payment promise validation failed: {0}")]
InvalidPaymentPromise(String),

#[error("host not found for validator {0}")]
HostNotFound(String),

It is easier to write those errors, but this approach has several drawbacks:

  1. String formatting and allocation is forced in the place where error is happened. Ideally error should be formatted at transport level, if needed at all.
  2. It makes it harder to analyze them by caller.

Suggested approach:

  1. Analyze how existing errors are constructed, and use format params as error params itself, and keep string formatting in thiserror macro.
  2. Extract some larger enums into new error enum and use #[from]. For example InvalidPaymentPromise is a good candidate for it.

Ideally all FibreErrors should be carefully examined and checked for duplication and simplication

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions