1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
// # Errors
// Defines a struct for errors and an enum which enumerates the error types
// ## Prelude
use crate::*;
use crate::nodes::{SourceRange, Token};
type Rows = usize;
type Cols = usize;
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct MechError {
pub id: u32,
pub tokens: Vec<Token>,
pub kind: MechErrorKind,
pub msg: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct ParserErrorContext {
pub cause_rng: SourceRange,
pub err_message: String,
pub annotation_rngs: Vec<SourceRange>,
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum MechErrorKind {
UndefinedField(u64), // Accessed a field of a record that's not defined
UndefinedVariable(u64), // Accessed a variable that's not defined
MissingTable(TableId), // TableId of missing table
MissingBlock(BlockId), // BlockId of missing block
PendingExpression, // id of pending variable
PendingTable(TableId), // TableId of pending table
DimensionMismatch(Vec<(Rows,Cols)>), // Argument dimensions are mismatched ((row,col),(row,col))
//MissingColumn((TableId,TableIndex)), // The identified table is missing a needed column
//ColumnKindMismatch(Vec<ValueKind>), // Excepted kind versus given kind
//SubscriptOutOfBounds(((Rows,Cols),(Rows,Cols))), // (target) vs (actual) index
LinearSubscriptOutOfBounds((Rows,Rows)), // (target) vs (actual) index
DuplicateAlias(u64), // Alias ID
//DomainMismatch(u64, u64), // domain IDs (target vs actual)
MissingFunction(u64), // ID of missing function
//TransformationPending(Transformation), // Block is unsatisfied so the transformation is not added
//IncorrectFunctionArgumentType,
ZeroIndex, // Zero cannot ever be used as an index.
BlockDisabled,
IoError,
GenericError(String),
FileNotFound(String),
Unhandled,
OutputUndefinedInFunctionBody(u64),
UnknownFunctionArgument(u64),
UnknownColumnKind(u64),
UnhandledFunctionArgumentKind,
IncorrectNumberOfArguments,
UnhandledTableShape(TableShape),
TooManyInputArguments(usize,usize), // (given,expected)
ParserError(nodes::ParserNode, ParserErrorReport, String),
MissingCapability(Capability),
InvalidCapabilityToken,
None,
}
impl From<std::io::Error> for MechError {
fn from(n: std::io::Error) -> MechError {
MechError{tokens: vec![], msg: "".to_string(), id: 74892, kind: MechErrorKind::IoError}
}
}
/*
impl fmt::Debug for MechErrorKind {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
_ => write!(f,"No Format")?;
}
Ok(())
}
}*/