flow_value/error.rs
1//! The two ways an operation in this crate can decline.
2
3use std::fmt;
4
5/// Why an arithmetic operation produced no value.
6///
7/// `data.md` makes a zero divisor the only operation on its types that faults.
8/// The evaluator turns either of these into a fault; neither is a value a
9/// program can observe.
10#[derive(Clone, Copy, PartialEq, Eq, Debug)]
11pub enum Fault {
12 /// `int.div`, `%` or `/` was given a zero divisor.
13 DivisionByZero,
14 /// The exact result exists but its scale cannot be represented: a
15 /// `Decimal` whose power of ten falls outside a signed 64-bit exponent.
16 ///
17 /// This is a host limit in `errors.md`'s sense, of a kind with running out
18 /// of memory for a large `Int`, not a rule about the number.
19 Limit,
20}
21
22impl fmt::Display for Fault {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 f.write_str(match self {
25 Fault::DivisionByZero => "division by zero",
26 Fault::Limit => "the result's scale exceeds what this host represents",
27 })
28 }
29}
30
31impl std::error::Error for Fault {}
32
33/// Why equality, ordering or text was refused.
34///
35/// `types.md` makes each of these a compile error on a type that is not data,
36/// so a checked program never reaches either case. They exist so that a defect
37/// upstream surfaces as a typed refusal rather than as an answer invented here.
38#[derive(Clone, Copy, PartialEq, Eq, Debug)]
39pub enum DataError {
40 /// A function, a task, a host token or another evaluator-owned value was
41 /// reached: none of them has equality, an order or a text form.
42 NotData,
43 /// The two values are not of one type.
44 Mismatch,
45}
46
47impl fmt::Display for DataError {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 f.write_str(match self {
50 DataError::NotData => "the value is not data",
51 DataError::Mismatch => "the values are not of one type",
52 })
53 }
54}
55
56impl std::error::Error for DataError {}