aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr/src/errors.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-13 16:03:57 +0100
committerGitHub <[email protected]>2020-08-13 16:03:57 +0100
commitd2212a49f6d447a14cdc87a9de2a4844e78b6905 (patch)
treeb9c7e76342b631709ecc7cea807dd82a43539312 /crates/ssr/src/errors.rs
parente9926948ca267932ccc1341388bfd1b3fa88a001 (diff)
parentae3abd6e575940eb1221acf26c09e96352f052fa (diff)
Merge #5748
5748: Rename ra_ssr -> ssr r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ssr/src/errors.rs')
-rw-r--r--crates/ssr/src/errors.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/ssr/src/errors.rs b/crates/ssr/src/errors.rs
new file mode 100644
index 000000000..c02bacae6
--- /dev/null
+++ b/crates/ssr/src/errors.rs
@@ -0,0 +1,29 @@
1//! Code relating to errors produced by SSR.
2
3/// Constructs an SsrError taking arguments like the format macro.
4macro_rules! _error {
5 ($fmt:expr) => {$crate::SsrError::new(format!($fmt))};
6 ($fmt:expr, $($arg:tt)+) => {$crate::SsrError::new(format!($fmt, $($arg)+))}
7}
8pub(crate) use _error as error;
9
10/// Returns from the current function with an error, supplied by arguments as for format!
11macro_rules! _bail {
12 ($($tokens:tt)*) => {return Err(crate::errors::error!($($tokens)*))}
13}
14pub(crate) use _bail as bail;
15
16#[derive(Debug, PartialEq)]
17pub struct SsrError(pub(crate) String);
18
19impl std::fmt::Display for SsrError {
20 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
21 write!(f, "Parse error: {}", self.0)
22 }
23}
24
25impl SsrError {
26 pub(crate) fn new(message: impl Into<String>) -> SsrError {
27 SsrError(message.into())
28 }
29}