diff options
author | David Lattimore <[email protected]> | 2020-06-23 13:03:39 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-03 23:56:51 +0100 |
commit | a5ef644a16f6d187fb6b612d30f19bf4f20fc6c4 (patch) | |
tree | d107edd6fa6a70e53c08300b25b9605a90eb80c9 /crates/ra_ssr/src/errors.rs | |
parent | 57ed622ec4f0f71a618f99a46aa0026e81eb2583 (diff) |
SSR: Extract error code out to a separate module
This is to make reusing it outside of parsing easier in a subsequent
change.
Diffstat (limited to 'crates/ra_ssr/src/errors.rs')
-rw-r--r-- | crates/ra_ssr/src/errors.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/errors.rs b/crates/ra_ssr/src/errors.rs new file mode 100644 index 000000000..c02bacae6 --- /dev/null +++ b/crates/ra_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. | ||
4 | macro_rules! _error { | ||
5 | ($fmt:expr) => {$crate::SsrError::new(format!($fmt))}; | ||
6 | ($fmt:expr, $($arg:tt)+) => {$crate::SsrError::new(format!($fmt, $($arg)+))} | ||
7 | } | ||
8 | pub(crate) use _error as error; | ||
9 | |||
10 | /// Returns from the current function with an error, supplied by arguments as for format! | ||
11 | macro_rules! _bail { | ||
12 | ($($tokens:tt)*) => {return Err(crate::errors::error!($($tokens)*))} | ||
13 | } | ||
14 | pub(crate) use _bail as bail; | ||
15 | |||
16 | #[derive(Debug, PartialEq)] | ||
17 | pub struct SsrError(pub(crate) String); | ||
18 | |||
19 | impl 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 | |||
25 | impl SsrError { | ||
26 | pub(crate) fn new(message: impl Into<String>) -> SsrError { | ||
27 | SsrError(message.into()) | ||
28 | } | ||
29 | } | ||