Skip to content

Commit e7c573f

Browse files
convert the Display impl to use displaydoc
1 parent 2bea25a commit e7c573f

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/protocol/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ log = "0.4"
2929
num_enum = "0.5.1"
3030
uuid = "0.8"
3131
thiserror = "1.0.24"
32+
displaydoc = "0.2"
3233

3334
[dependencies.curve25519-dalek]
3435
features = ["serde", "alloc"]

rust/protocol/src/error.rs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use crate::curve::KeyType;
77

8+
use displaydoc::Display;
89
use thiserror::Error;
910

1011
use std::fmt;
@@ -35,89 +36,89 @@ impl std::error::Error for CallbackErrorWrapper {
3536
}
3637
}
3738

38-
#[derive(Debug, Error)]
39+
#[derive(Debug, Display, Error)]
3940
pub enum SignalProtocolError {
40-
#[error("invalid argument: {}", .0)]
41+
/// invalid argument: {0}
4142
InvalidArgument(String),
42-
#[error("invalid state for call to {} to succeed: {}", .0, .1)]
43+
/// invalid state for call to {0} to succeed: {1}
4344
InvalidState(&'static str, String),
4445

45-
#[error("failed to decode protobuf: {}", .0)]
46+
/// failed to decode protobuf: {0}
4647
ProtobufDecodingError(#[from] prost::DecodeError),
47-
#[error("failed to encode protobuf: {}", .0)]
48+
/// failed to encode protobuf: {0}
4849
ProtobufEncodingError(#[from] prost::EncodeError),
49-
#[error("protobuf encoding was invalid")]
50+
/// protobuf encoding was invalid
5051
InvalidProtobufEncoding,
5152

52-
#[error("ciphertext serialized bytes were too short <{}>", .0)]
53+
/// ciphertext serialized bytes were too short <{0}>
5354
CiphertextMessageTooShort(usize),
54-
#[error("ciphertext version was too old <{}>", .0)]
55+
/// ciphertext version was too old <{0}>
5556
LegacyCiphertextVersion(u8),
56-
#[error("ciphertext version was unrecognized <{}>", .0)]
57+
/// ciphertext version was unrecognized <{0}>
5758
UnrecognizedCiphertextVersion(u8),
58-
#[error("unrecognized message version <{}>", .0)]
59+
/// unrecognized message version <{0}>
5960
UnrecognizedMessageVersion(u32),
6061

61-
#[error("fingerprint identifiers do not match")]
62+
/// fingerprint identifiers do not match
6263
FingerprintIdentifierMismatch,
63-
#[error("fingerprint version number mismatch them {} us {}", .0, .1)]
64+
/// fingerprint version number mismatch them {0} us {1}
6465
FingerprintVersionMismatch(u32, u32),
65-
#[error("fingerprint parsing error")]
66+
/// fingerprint parsing error
6667
FingerprintParsingError,
6768

68-
#[error("no key type identifier")]
69+
/// no key type identifier
6970
NoKeyTypeIdentifier,
70-
#[error("bad key type <{:#04x}>", .0)]
71+
/// bad key type <{0:#04x}>
7172
BadKeyType(u8),
72-
#[error("bad key length <{}> for key with type <{}>", .1, .0)]
73+
/// bad key length <{0}> for key with type <{1}>
7374
BadKeyLength(KeyType, usize),
7475

75-
#[error("invalid signature detected")]
76+
/// invalid signature detected
7677
SignatureValidationFailed,
7778

78-
#[error("untrusted identity for address {}", .0)]
79+
/// untrusted identity for address {0}
7980
UntrustedIdentity(crate::ProtocolAddress),
8081

81-
#[error("invalid prekey identifier")]
82+
/// invalid prekey identifier
8283
InvalidPreKeyId,
83-
#[error("invalid signed prekey identifier")]
84+
/// invalid signed prekey identifier
8485
InvalidSignedPreKeyId,
8586

86-
#[error("invalid root key length <{}>", .0)]
87+
/// invalid root key length <{0}>
8788
InvalidRootKeyLength(usize),
88-
#[error("invalid chain key length <{}>", .0)]
89+
/// invalid chain key length <{0}>
8990
InvalidChainKeyLength(usize),
9091

91-
#[error("invalid MAC key length <{}>", .0)]
92+
/// invalid MAC key length <{0}>
9293
InvalidMacKeyLength(usize),
93-
#[error("invalid cipher key length <{}> or nonce length <{}>", .0, .1)]
94+
/// invalid cipher key length <{0}> or nonce length <{1}>
9495
InvalidCipherCryptographicParameters(usize, usize),
95-
#[error("invalid ciphertext message")]
96+
/// invalid ciphertext message
9697
InvalidCiphertext,
9798

98-
#[error("no sender key state")]
99+
/// no sender key state
99100
NoSenderKeyState,
100101

101-
#[error("session with '{}' not found", .0)]
102+
/// session with '{0}' not found
102103
SessionNotFound(String),
103-
#[error("invalid session structure")]
104+
/// invalid session structure
104105
InvalidSessionStructure,
105106

106-
#[error("message with old counter {} / {}", .0, .1)]
107+
/// message with old counter {0} / {1}
107108
DuplicatedMessage(u32, u32),
108-
#[error("invalid message {}", .0)]
109+
/// invalid message {0}
109110
InvalidMessage(&'static str),
110-
#[error("internal error {}", .0)]
111+
/// internal error {0}
111112
InternalError(&'static str),
112-
#[error("error while invoking an ffi callback: {}", .0)]
113+
/// error while invoking an ffi callback: {0}
113114
FfiBindingError(String),
114-
#[error("error in method call '{}': {}", .0, .1)]
115+
/// error in method call '{0}': {1}
115116
ApplicationCallbackError(&'static str, #[source] CallbackErrorWrapper),
116117

117-
#[error("invalid sealed sender message {}", .0)]
118+
/// invalid sealed sender message {0}
118119
InvalidSealedSenderMessage(String),
119-
#[error("unknown sealed sender message version {}", .0)]
120+
/// unknown sealed sender message version {0}
120121
UnknownSealedSenderVersion(u8),
121-
#[error("self send of a sealed sender message")]
122+
/// self send of a sealed sender message
122123
SealedSenderSelfSend,
123124
}

0 commit comments

Comments
 (0)