Skip to main content

prov_exports/
error.rs

1//! What can go wrong planning an export.
2
3use std::fmt;
4
5/// The result of planning an export.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// An export could not be planned.
9#[derive(Debug)]
10pub enum Error {
11    /// Reading the workspace failed.
12    Graph(prov_graph::error::Error),
13    /// The export names a view and that view could not be executed — its
14    /// anchor resolves to nothing, or the read under it failed.
15    ///
16    /// Passed through rather than softened to "no view", because the two mean
17    /// opposite things: an export whose view is broken must not fall back to
18    /// exporting the gate's whole set. That would be the valve failing *open*.
19    View(prov_views::Error),
20    /// The export names a view this workspace does not declare.
21    ///
22    /// An error, not an unarranged export, for the same reason: the absent
23    /// view was written down as a bound on what leaves, and the fail-closed
24    /// reading of a bound nobody can find is to export nothing.
25    ViewUnknown {
26        /// The export that named it.
27        export: String,
28        /// The view name exactly as written.
29        view: String,
30    },
31}
32
33impl fmt::Display for Error {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        match self {
36            Error::Graph(e) => write!(f, "{e}"),
37            Error::View(e) => write!(f, "{e}"),
38            Error::ViewUnknown { export, view } => write!(
39                f,
40                "the export `{export}` is arranged by the view `{view}`, \
41                 but this workspace declares no view by that name"
42            ),
43        }
44    }
45}
46
47impl std::error::Error for Error {
48    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
49        match self {
50            Error::Graph(e) => Some(e),
51            Error::View(e) => Some(e),
52            Error::ViewUnknown { .. } => None,
53        }
54    }
55}
56
57impl From<prov_graph::error::Error> for Error {
58    fn from(error: prov_graph::error::Error) -> Self {
59        Error::Graph(error)
60    }
61}
62
63impl From<prov_views::Error> for Error {
64    fn from(error: prov_views::Error) -> Self {
65        Error::View(error)
66    }
67}