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:
- 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.
- It makes it harder to analyze them by caller.
Suggested approach:
- Analyze how existing errors are constructed, and use format params as error params itself, and keep string formatting in thiserror macro.
- 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
Currently there are several error variants in FibreClient crate, which are just wrapped string, for example:
lumina/fibre/src/domain/error.rs
Lines 36 to 41 in 960a0b5
lumina/fibre/src/domain/error.rs
Lines 72 to 73 in 960a0b5
lumina/fibre/src/domain/error.rs
Lines 82 to 83 in 960a0b5
lumina/fibre/src/domain/error.rs
Lines 87 to 88 in 960a0b5
It is easier to write those errors, but this approach has several drawbacks:
Suggested approach:
#[from]. For exampleInvalidPaymentPromiseis a good candidate for it.Ideally all FibreErrors should be carefully examined and checked for duplication and simplication