identifiers: Improve session_id! error messages
This commit is contained in:
parent
cb96caa064
commit
c3435a39e4
@ -167,7 +167,7 @@ macro_rules! session_id {
|
|||||||
($s:literal) => {{
|
($s:literal) => {{
|
||||||
const SESSION_ID: &$crate::SessionId = match $crate::SessionId::_priv_const_new($s) {
|
const SESSION_ID: &$crate::SessionId = match $crate::SessionId::_priv_const_new($s) {
|
||||||
Ok(id) => id,
|
Ok(id) => id,
|
||||||
Err(_) => panic!("Invalid session ID"),
|
Err(e) => panic!("{}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
SESSION_ID
|
SESSION_ID
|
||||||
|
@ -15,10 +15,17 @@ pub struct SessionId(str);
|
|||||||
|
|
||||||
impl SessionId {
|
impl SessionId {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub const fn _priv_const_new(s: &str) -> Result<&Self, IdParseError> {
|
pub const fn _priv_const_new(s: &str) -> Result<&Self, &'static str> {
|
||||||
match validate_session_id(s) {
|
match validate_session_id(s) {
|
||||||
Ok(()) => Ok(Self::from_borrowed(s)),
|
Ok(()) => Ok(Self::from_borrowed(s)),
|
||||||
Err(e) => Err(e),
|
Err(IdParseError::MaximumLengthExceeded) => {
|
||||||
|
Err("Invalid Session ID: exceeds 255 bytes")
|
||||||
|
}
|
||||||
|
Err(IdParseError::InvalidCharacters) => {
|
||||||
|
Err("Invalid Session ID: contains invalid characters")
|
||||||
|
}
|
||||||
|
Err(IdParseError::Empty) => Err("Invalid Session ID: empty"),
|
||||||
|
Err(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,6 @@ error[E0080]: evaluation of constant value failed
|
|||||||
--> tests/identifiers/ui/03-invalid-new-id-macros.rs:2:13
|
--> tests/identifiers/ui/03-invalid-new-id-macros.rs:2:13
|
||||||
|
|
|
|
||||||
2 | let _ = ruma_common::session_id!("invalid~");
|
2 | let _ = ruma_common::session_id!("invalid~");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Invalid session ID', $DIR/tests/identifiers/ui/03-invalid-new-id-macros.rs:2:13
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Invalid Session ID: contains invalid characters', $DIR/tests/identifiers/ui/03-invalid-new-id-macros.rs:2:13
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user