1use thiserror::Error;
2
3use crate::options::TerminalWidthProfile;
4use crate::resource::AsciiResourceLimitExceeded;
5
6pub type Result<T> = std::result::Result<T, AsciiError>;
7
8#[non_exhaustive]
9#[derive(Debug, Clone, Error, PartialEq, Eq)]
10pub enum AsciiError {
11 #[error(transparent)]
12 Cancelled(#[from] merman_core::OperationCancelled),
13 #[error("invalid ASCII render option `{field}`: {message}")]
14 InvalidOption {
15 field: &'static str,
16 message: &'static str,
17 },
18 #[error("ASCII rendering does not support diagram type `{diagram_type}`")]
19 UnsupportedDiagram { diagram_type: String },
20 #[error("ASCII rendering does not support `{feature}` for `{diagram_type}` yet")]
21 UnsupportedFeature {
22 diagram_type: &'static str,
23 feature: &'static str,
24 },
25 #[error("ASCII rendering could not allocate bounded storage during `{phase}`")]
26 AllocationFailed { phase: &'static str },
27 #[error(transparent)]
28 ResourceLimitExceeded(#[from] AsciiResourceLimitExceeded),
29 #[error(transparent)]
30 OperationResourceTerminal(merman_core::OperationLedgerError),
31 #[error(
32 "ASCII output exceeds requested width: actual {actual_width} cells > maximum {max_width} ({profile:?})"
33 )]
34 WidthOverflow {
35 max_width: usize,
36 actual_width: usize,
37 profile: TerminalWidthProfile,
38 },
39 #[error(
42 "ASCII primary projection exceeds fallback viewport: actual {actual_width} cells > maximum {max_width} ({profile:?})"
43 )]
44 PrimaryViewportOverflow {
45 max_width: usize,
46 actual_width: usize,
47 height: usize,
48 profile: TerminalWidthProfile,
49 },
50 #[error(
51 "ASCII structured fallback is unavailable for `{diagram_type}` within {max_width} cells (actual {actual_width})"
52 )]
53 FallbackUnavailable {
54 diagram_type: String,
55 max_width: usize,
56 actual_width: usize,
57 },
58}
59
60impl AsciiError {
61 pub(crate) const fn allocation_failed(phase: &'static str) -> Self {
62 Self::AllocationFailed { phase }
63 }
64}