1use std::fmt;
5
6pub const MAX_CALL_DEPTH: usize = 128;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub enum Failure {
13 DivideByZero,
14 TooLarge,
16 TooLong,
18 NegativePosition(i64),
19 NoItem {
20 position: usize,
21 len: usize,
22 },
23 TooDeep {
25 function: String,
26 },
27 DownloadIntoVariable,
28 DialogIntoVariable,
30 Dialog(String),
32}
33
34impl fmt::Display for Failure {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 match self {
37 Self::DivideByZero => f.write_str("can't divide by zero"),
38 Self::TooLarge => f.write_str("this number is too large"),
39 Self::TooLong => f.write_str("this is too long to count"),
40 Self::NegativePosition(index) => {
41 write!(f, "list positions start at 0, so {index} isn't one")
42 }
43 Self::NoItem { position, len } => {
44 write!(f, "there is no item {position}; the list has {len}")
45 }
46 Self::TooDeep { function } => {
47 write!(
48 f,
49 "`{function}` calls itself too deeply; does it ever stop?"
50 )
51 }
52 Self::DownloadIntoVariable => {
53 f.write_str("`download` can only report into state, not into a variable")
54 }
55 Self::DialogIntoVariable => {
56 f.write_str("a file dialog can only answer into state, not into a variable")
57 }
58 Self::Dialog(reason) => write!(f, "the file dialog failed: {reason}"),
59 }
60 }
61}