mech_core/error.rs
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94
// # Errors
// Defines a struct for errors and an enum which enumerates the error types
// ## Prelude
use crate::ValueKind;
use crate::nodes::{SourceRange, Token};
use std::fmt;
type Rows = usize;
type Cols = usize;
pub type ParserErrorReport = Vec<ParserErrorContext>;
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct MechError{
pub id: u32,
pub file: String,
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
UndefinedKind(u64), // Used a kind that's not defined
MissingTable(u64), // TableId of missing table
WrongTableColumnKind,
MissingBlock(u64), // BlockId of missing block
PendingExpression, // id of pending variable
PendingTable(u64), // TableId of pending table
DimensionMismatch(Vec<(Rows,Cols)>), // Argument dimensions are mismatched ((row,col),(row,col))
KindMismatch(ValueKind,ValueKind),
UnhandledIndexKind,
//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
//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.
VariableRedefined(u64),
NotMutable(u64),
BlockDisabled,
IoError,
GenericError(String),
FileNotFound(String),
Unhandled,
OutputUndefinedInFunctionBody(u64),
UnknownFunctionArgument(u64),
UnknownColumnKind(u64),
UnknownEnumVairant(u64,u64),
UnableToConvertValueKind,
UnhandledFunctionArgumentKind,
CouldNotAssignKindToValue,
ExpectedNumericForSize, // When something non-numeric is passed as a size
MatrixMustHaveHomogenousKind, // When multiple element kinds are specified for a matrix
IncorrectNumberOfArguments,
//UnhandledTableShape(TableShape),
TooManyInputArguments(usize,usize), // (given,expected)
ParserError(ParserErrorReport, String),
//MissingCapability(Capability),
InvalidCapabilityToken,
UnknownReplCommand(String),
NoCode,
None,
}
impl From<std::io::Error> for MechError{
fn from(n: std::io::Error) -> MechError{
MechError{file: file!().to_string(), 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(())
}
}*/