-
Notifications
You must be signed in to change notification settings - Fork 303
(draft) use n0-error #3511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
(draft) use n0-error #3511
Changes from all commits
68466be
9476e69
765f80c
135b357
5ef4d8f
b78ecce
8333928
face59e
e305b70
8107605
abdf366
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,8 @@ use std::{ | |
use curve25519_dalek::edwards::CompressedEdwardsY; | ||
pub use ed25519_dalek::{Signature, SignatureError}; | ||
use ed25519_dalek::{SigningKey, VerifyingKey}; | ||
use nested_enum_utils::common_fields; | ||
use rand_core::CryptoRng; | ||
use serde::{Deserialize, Serialize}; | ||
use snafu::{Backtrace, Snafu}; | ||
|
||
/// A public key. | ||
/// | ||
|
@@ -203,25 +201,22 @@ impl Display for PublicKey { | |
} | ||
|
||
/// Error when deserialising a [`PublicKey`] or a [`SecretKey`]. | ||
#[common_fields({ | ||
backtrace: Option<Backtrace>, | ||
#[snafu(implicit)] | ||
span_trace: n0_snafu::SpanTrace, | ||
})] | ||
#[derive(Snafu, Debug)] | ||
#[n0_error::add_location] | ||
#[derive(n0_error::Error)] | ||
#[error(from_sources, std_sources)] | ||
#[allow(missing_docs)] | ||
#[snafu(visibility(pub(crate)))] | ||
#[non_exhaustive] | ||
pub enum KeyParsingError { | ||
/// Error when decoding. | ||
#[snafu(transparent)] | ||
#[error(transparent)] | ||
Decode { source: data_encoding::DecodeError }, | ||
/// Error when decoding the public key. | ||
#[snafu(transparent)] | ||
#[error(transparent)] | ||
Key { | ||
source: ed25519_dalek::SignatureError, | ||
}, | ||
/// The encoded information had the wrong length. | ||
#[snafu(display("invalid length"))] | ||
#[display("invalid length")] | ||
DecodeInvalidLength {}, | ||
} | ||
|
||
|
@@ -353,14 +348,14 @@ fn decode_base32_hex(s: &str) -> Result<[u8; 32], KeyParsingError> { | |
let input = s.to_ascii_uppercase(); | ||
let input = input.as_bytes(); | ||
if data_encoding::BASE32_NOPAD.decode_len(input.len())? != bytes.len() { | ||
return Err(DecodeInvalidLengthSnafu.build()); | ||
return Err(KeyParsingError::decode_invalid_length()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this means rust-analyzer "find-all-references" on That's one of the main usability issues I have with snafu. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is true unfortunately. And I agree that fixing this would be a major improvement.
I am undecided yet. Wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First note that I'm spouting ideas without much knowledge of how things need to be wired up. So I might be suggesting nonsense. Maybe 1.2 is workable. I think you can also write this as Maybe another option could be to use yet another macro to create the structs itself, like It seems like 2 is much more the "Error + ErrorKind" type of approach. At first it does look appealing. But yeah, depends on the ergonomics of all the edge cases. Also matching on errors could become a little more awkward, I really like being able to write match statements without having to do the nested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.2 could also be The generic error matching wouldn't be too bad: we could define it as |
||
} | ||
data_encoding::BASE32_NOPAD.decode_mut(input, &mut bytes) | ||
}; | ||
match res { | ||
Ok(len) => { | ||
if len != PublicKey::LENGTH { | ||
return Err(DecodeInvalidLengthSnafu.build()); | ||
return Err(KeyParsingError::decode_invalid_length()); | ||
} | ||
} | ||
Err(partial) => return Err(partial.error.into()), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be good if we can restrict these methods to be crate only, to not make them part of the public api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking about this some more, we will want to be able to be able to configure visibility on a variant level, eg this error