Skip to main content

tablo_core/declaration/
mount_error.rs

1//! [`MountError`], every mistake a refused panel declares.
2
3use std::fmt;
4
5use super::DeclarationError;
6
7/// Why [`RouterBuilderPanelExt::panel`](crate::RouterBuilderPanelExt::panel) refused a panel:
8/// every declaration mistake it found.
9///
10/// The router's builder returns it as a [`topcoat::Error`]; recover it with
11/// `error.downcast_ref::<MountError>()`.
12#[derive(Debug)]
13pub struct MountError {
14    panel: String,
15    errors: Vec<DeclarationError>,
16}
17
18impl MountError {
19    pub(crate) fn new(panel: &str, errors: Vec<DeclarationError>) -> Self {
20        Self {
21            panel: panel.to_string(),
22            errors,
23        }
24    }
25
26    /// The refused panel's prefix.
27    pub fn panel(&self) -> &str {
28        &self.panel
29    }
30
31    /// Every mistake found, in declaration order.
32    pub fn errors(&self) -> &[DeclarationError] {
33        &self.errors
34    }
35}
36
37impl fmt::Display for MountError {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        write!(f, "panel '{}' cannot mount:", self.panel)?;
40        for error in &self.errors {
41            write!(f, "\n  - {error}")?;
42        }
43        Ok(())
44    }
45}
46
47impl std::error::Error for MountError {}