chore: implement Display for error types#879
chore: implement Display for error types#879Micah-Shallom wants to merge 1 commit intogetfloresta:masterfrom
Conversation
moisesPompilio
left a comment
There was a problem hiding this comment.
The commit is missing a description; it only has the title
| use crate::ChainStore; | ||
| use crate::DatabaseError; | ||
| use crate::DiskBlockHeader; | ||
| use core::fmt; |
There was a problem hiding this comment.
I think the position of this import is not here; did you get to run the format or lint on the code?
There was a problem hiding this comment.
My bad.. I have amended this..Thanks
f336be8 to
06ba469
Compare
jaoleal
left a comment
There was a problem hiding this comment.
Heres some superficial review. Still need to check if the imports are correct
| FlatChainstoreError::Io(e) => write!(f, "I/O error: {}", e), | ||
| FlatChainstoreError::BlockNotFound => write!(f, "Block not found"), | ||
| FlatChainstoreError::IndexIsFull => write!(f, "Index is full"), | ||
| FlatChainstoreError::DbTooNew(v) => write!(f, "Database too new: {}", v), |
There was a problem hiding this comment.
| FlatChainstoreError::DbTooNew(v) => write!(f, "Database too new: {}", v), | |
| FlatChainstoreError::DbTooNew(v) => write!(f, "Database too new: {v}"), |
| impl fmt::Display for FlatChainstoreError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| FlatChainstoreError::Io(e) => write!(f, "I/O error: {}", e), |
There was a problem hiding this comment.
| FlatChainstoreError::Io(e) => write!(f, "I/O error: {}", e), | |
| FlatChainstoreError::Io(e) => write!(f, "I/O error: {e}"), |
| FlatChainstoreError::IndexIsFull => write!(f, "Index is full"), | ||
| FlatChainstoreError::DbTooNew(v) => write!(f, "Database too new: {}", v), | ||
| FlatChainstoreError::Poisoned => write!(f, "Poisoned"), | ||
| FlatChainstoreError::InvalidMagic(m) => write!(f, "Invalid magic: {}", m), |
There was a problem hiding this comment.
| FlatChainstoreError::InvalidMagic(m) => write!(f, "Invalid magic: {}", m), | |
| FlatChainstoreError::InvalidMagic(m) => write!(f, "Invalid magic: {m}"), |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| LeafErrorKind::EmptyStack => write!(f, "Empty stack"), | ||
| LeafErrorKind::InvalidInstruction(e) => write!(f, "Invalid instruction: {}", e), |
There was a problem hiding this comment.
| LeafErrorKind::InvalidInstruction(e) => write!(f, "Invalid instruction: {}", e), | |
| LeafErrorKind::InvalidInstruction(e) => write!(f, "Invalid instruction: {e}"), |
| impl fmt::Display for HeaderExtError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| HeaderExtError::Chain(e) => write!(f, "Chain error: {}", e), |
There was a problem hiding this comment.
| HeaderExtError::Chain(e) => write!(f, "Chain error: {}", e), | |
| HeaderExtError::Chain(e) => write!(f, "Chain error: {e}"), |
crates/floresta-node/src/slip132.rs
Outdated
| Error::InvalidChildNumberFormat => write!(f, "Invalid child number format"), | ||
| Error::InvalidDerivationPathFormat => write!(f, "Invalid derivation path format"), | ||
| Error::UnknownVersion(v) => write!(f, "Unknown version: {:?}", v), | ||
| Error::WrongExtendedKeyLength(l) => write!(f, "Wrong extended key length: {}", l), |
There was a problem hiding this comment.
| Error::WrongExtendedKeyLength(l) => write!(f, "Wrong extended key length: {}", l), | |
| Error::WrongExtendedKeyLength(l) => write!(f, "Wrong extended key length: {I}"), |
| type Result<T> = floresta_common::prelude::Result<T, MemoryDatabaseError>; | ||
|
|
||
| impl Display for MemoryDatabaseError { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
There was a problem hiding this comment.
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| fn fmt(&self, f: &mut Formatter<'_>) -> Result { |
| impl fmt::Display for BlockchainBuilderError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
There was a problem hiding this comment.
Not sure if those could be called withtout fmt::. If theres any conflict you can leave as it is, besides that, prefer importing
There was a problem hiding this comment.
importing would work for Display and FOrmatter but wouldnt for Result due to shadowing of Rusts's default Result with the one we define.....so i just decided to use fmt:: for all of them for uniformity instead of mixing prefixed and unprefixed imports
There was a problem hiding this comment.
Import like this:
use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter| impl fmt::Display for FlatChainstoreError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { |
There was a problem hiding this comment.
| impl fmt::Display for LeafErrorKind { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
There was a problem hiding this comment.
|
See: #876 |
|
@jaoleal thanks for you reviews.. i looked at #876 you pointed me to... noticed @luisschwab also raised the same issue where there would be a conflict with the non-fmt Result preluded automatically by rust I'll make |
06ba469 to
993dfd5
Compare
993dfd5 to
a4c83a6
Compare
a4c83a6 to
dcab56a
Compare
|
hi @moisesPompilio , all review feedback has been addressed on this PR.....would appreciate a re-review..thank you. |
| BlockchainBuilderError::MissingChainstore => write!(f, "Missing chainstore"), | ||
| BlockchainBuilderError::MissingChainParams => write!(f, "Missing chain parameters"), | ||
| BlockchainBuilderError::IncompleteTip => write!(f, "Incomplete tip"), | ||
| BlockchainBuilderError::Database(e) => write!(f, "Database error: {:?}", e), |
There was a problem hiding this comment.
| BlockchainBuilderError::Database(e) => write!(f, "Database error: {:?}", e), | |
| BlockchainBuilderError::Database(e) => write!(f, "Database error: {e:?}"), |
crates/floresta-node/src/slip132.rs
Outdated
| Error::InvalidChildNumber(n) => write!(f, "Invalid child number: {}", n), | ||
| Error::InvalidChildNumberFormat => write!(f, "Invalid child number format"), | ||
| Error::InvalidDerivationPathFormat => write!(f, "Invalid derivation path format"), | ||
| Error::UnknownVersion(v) => write!(f, "Unknown version: {:?}", v), |
There was a problem hiding this comment.
This still needs to be applied.
Implement Display trait for error types that were missing it, enabling integration with thiserror and #[error(transparent)]. Error types updated: MemoryDatabaseError, HeaderExtError, FlatChainstoreError, BlockchainBuilderError, LeafErrorKind, slip132::Error.
dcab56a to
1c97642
Compare
|
@Micah-Shallom please don't request reviews like this. I removed it for a reason. |
|
apologies @luisschwab ....i didnt know you removed it and thought my network was bad and so i kept punching the request review button... |

Description
Closes #667.
Implements
Displayfor all error types that were missing it, allowing them to be integrated into custom error types usingthiserrorand#[error(transparent)].Error Types Updated
floresta-watch-onlyfloresta-chainfloresta-chainfloresta-chainfloresta-chainfloresta-nodeAI was used to help identify error types missing Display implementations across the codebase