1use crate::errors::{Diagnostic, OperationFailure};
4
5#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9 #[error("I/O error: {0}")]
11 Io(#[from] std::io::Error),
12 #[error("data error: {0}")]
14 Data(Diagnostic),
15 #[error("render error: {0}")]
17 Render(Diagnostic),
18 #[error(transparent)]
20 Operation(Box<OperationFailure>),
21 #[error("operation cancelled")]
23 Cancelled,
24}
25
26impl Error {
27 pub(crate) fn with_prefix(self, prefix: &str) -> Self {
28 match self {
29 Self::Data(diagnostic) => Self::Data(diagnostic.with_prefix(prefix)),
30 Self::Render(diagnostic) => Self::Render(diagnostic.with_prefix(prefix)),
31 other => other,
34 }
35 }
36
37 pub fn diagnostic(&self) -> Option<&Diagnostic> {
39 match self {
40 Self::Data(diagnostic) | Self::Render(diagnostic) => Some(diagnostic),
41 Self::Operation(failure) => failure.cause().diagnostic(),
42 _ => None,
43 }
44 }
45}
46
47impl From<std::convert::Infallible> for Error {
48 fn from(value: std::convert::Infallible) -> Self {
49 match value {}
50 }
51}
52
53pub type Result<T> = std::result::Result<T, Error>;