kaymyg
Add kaysentinel-protocol crate: implementation-neutral shared error type (PR 1 / File 1)
15637c2 Download runtime/protocol/src/errors.rs from Sahek/kaysentinel: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/Sahek/kaysentinel/resolve/main/runtime/protocol/src/errors.rs
- Command line
-
hf download hf://Sahek/kaysentinel/runtime/protocol/src/errors.rs
-
curl -L -o errors.rs https://huggingface.co/Sahek/kaysentinel/resolve/main/runtime/protocol/src/errors.rs
1.77 kB
| use std::fmt; | |
| pub enum ProtocolError { | |
| /// Returned when the block or epoch index violates genesis state constraints. | |
| InvalidGenesisContext, | |
| /// Returned when a list or vector length violates specified maximum protocol boundaries. | |
| LengthLimitExceeded, | |
| /// Returned when input data collections fail the required pre-sorted validation check. | |
| NonCanonicalInputOrder, | |
| } | |
| impl fmt::Display for ProtocolError { | |
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| match self { | |
| ProtocolError::InvalidGenesisContext => write!(f, "invalid genesis context"), | |
| ProtocolError::LengthLimitExceeded => write!(f, "length limit exceeded"), | |
| ProtocolError::NonCanonicalInputOrder => write!(f, "input is not in canonical order"), | |
| } | |
| } | |
| } | |
| impl std::error::Error for ProtocolError {} | |
| mod tests { | |
| use super::*; | |
| fn display_messages_are_implementation_neutral() { | |
| // The public error message text should read naturally without leaking | |
| // Rust-specific enum variant naming (CamelCase, no "Error::" prefix, etc.) | |
| // — that's the whole point of having a Display impl instead of exposing | |
| // Debug output to callers. | |
| assert_eq!(ProtocolError::InvalidGenesisContext.to_string(), "invalid genesis context"); | |
| assert_eq!(ProtocolError::LengthLimitExceeded.to_string(), "length limit exceeded"); | |
| assert_eq!(ProtocolError::NonCanonicalInputOrder.to_string(), "input is not in canonical order"); | |
| } | |
| fn implements_std_error() { | |
| fn assert_is_std_error<E: std::error::Error>(_: E) {} | |
| assert_is_std_error(ProtocolError::LengthLimitExceeded); | |
| } | |
| } | |