Skip to content

Commit 9df218d

Browse files
convert the Display impl to use displaydoc
1 parent c557eb0 commit 9df218d

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;
@@ -37,89 +38,89 @@ impl std::error::Error for CallbackErrorWrapper {
3738
}
3839
}
3940

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

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

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

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

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

77-
#[error("invalid signature detected")]
78+
/// invalid signature detected
7879
SignatureValidationFailed,
7980

80-
#[error("untrusted identity for address {}", .0)]
81+
/// untrusted identity for address {0}
8182
UntrustedIdentity(crate::ProtocolAddress),
8283

83-
#[error("invalid prekey identifier")]
84+
/// invalid prekey identifier
8485
InvalidPreKeyId,
85-
#[error("invalid signed prekey identifier")]
86+
/// invalid signed prekey identifier
8687
InvalidSignedPreKeyId,
8788

88-
#[error("invalid root key length <{}>", .0)]
89+
/// invalid root key length <{0}>
8990
InvalidRootKeyLength(usize),
90-
#[error("invalid chain key length <{}>", .0)]
91+
/// invalid chain key length <{0}>
9192
InvalidChainKeyLength(usize),
9293

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

100-
#[error("no sender key state")]
101+
/// no sender key state
101102
NoSenderKeyState,
102103

103-
#[error("session with '{}' not found", .0)]
104+
/// session with '{0}' not found
104105
SessionNotFound(String),
105-
#[error("invalid session structure")]
106+
/// invalid session structure
106107
InvalidSessionStructure,
107108

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

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

0 commit comments

Comments
 (0)