From 60129b7d1c0ea8bdf2ec666fa51957e97465e88f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 6 May 2019 23:17:26 +0200 Subject: Consolidate errors in the error module --- dhall/src/error.rs | 60 -------- dhall/src/error/mod.rs | 169 +++++++++++++++++++++ dhall/src/error/text/AnnotMismatch.txt | 117 ++++++++++++++ dhall/src/error/text/CantTextAppend.txt | 28 ++++ dhall/src/error/text/DuplicateAlternative.txt | 18 +++ dhall/src/error/text/FieldCollision.txt | 43 ++++++ dhall/src/error/text/HandlerInputTypeMismatch.txt | 49 ++++++ dhall/src/error/text/HandlerNotAFunction.txt | 32 ++++ dhall/src/error/text/HandlerOutputTypeMismatch.txt | 51 +++++++ dhall/src/error/text/IfBranchMismatch.txt | 63 ++++++++ dhall/src/error/text/IfBranchMustBeTerm.txt | 51 +++++++ dhall/src/error/text/InvalidAlterantive.txt | 48 ++++++ dhall/src/error/text/InvalidAlterantiveType.txt | 49 ++++++ dhall/src/error/text/InvalidField.txt | 35 +++++ dhall/src/error/text/InvalidFieldType.txt | 34 +++++ dhall/src/error/text/InvalidInputType.txt | 61 ++++++++ dhall/src/error/text/InvalidListElement.txt | 30 ++++ dhall/src/error/text/InvalidListType.txt | 43 ++++++ dhall/src/error/text/InvalidOptionType.txt | 44 ++++++ dhall/src/error/text/InvalidOptionalElement.txt | 29 ++++ dhall/src/error/text/InvalidOptionalLiteral.txt | 53 +++++++ dhall/src/error/text/InvalidOutputType.txt | 68 +++++++++ dhall/src/error/text/InvalidPredicate.txt | 51 +++++++ dhall/src/error/text/MissingField.txt | 30 ++++ dhall/src/error/text/MissingHandler.txt | 32 ++++ dhall/src/error/text/MustCombineARecord.txt | 46 ++++++ dhall/src/error/text/MustMergeARecord.txt | 43 ++++++ dhall/src/error/text/MustMergeUnion.txt | 31 ++++ dhall/src/error/text/NoDependentLet.txt | 76 +++++++++ dhall/src/error/text/NoDependentTypes.txt | 31 ++++ dhall/src/error/text/NotAFunction.txt | 68 +++++++++ dhall/src/error/text/NotARecord.txt | 48 ++++++ dhall/src/error/text/TypeMismatch.txt | 117 ++++++++++++++ dhall/src/error/text/UnboundVariable.txt | 97 ++++++++++++ dhall/src/error/text/Untyped.txt | 117 ++++++++++++++ dhall/src/error/text/UnusedHandler.txt | 32 ++++ dhall/src/errors/AnnotMismatch.txt | 117 -------------- dhall/src/errors/CantTextAppend.txt | 28 ---- dhall/src/errors/DuplicateAlternative.txt | 18 --- dhall/src/errors/FieldCollision.txt | 43 ------ dhall/src/errors/HandlerInputTypeMismatch.txt | 49 ------ dhall/src/errors/HandlerNotAFunction.txt | 32 ---- dhall/src/errors/HandlerOutputTypeMismatch.txt | 51 ------- dhall/src/errors/IfBranchMismatch.txt | 63 -------- dhall/src/errors/IfBranchMustBeTerm.txt | 51 ------- dhall/src/errors/InvalidAlterantive.txt | 48 ------ dhall/src/errors/InvalidAlterantiveType.txt | 49 ------ dhall/src/errors/InvalidField.txt | 35 ----- dhall/src/errors/InvalidFieldType.txt | 34 ----- dhall/src/errors/InvalidInputType.txt | 61 -------- dhall/src/errors/InvalidListElement.txt | 30 ---- dhall/src/errors/InvalidListType.txt | 43 ------ dhall/src/errors/InvalidOptionType.txt | 44 ------ dhall/src/errors/InvalidOptionalElement.txt | 29 ---- dhall/src/errors/InvalidOptionalLiteral.txt | 53 ------- dhall/src/errors/InvalidOutputType.txt | 68 --------- dhall/src/errors/InvalidPredicate.txt | 51 ------- dhall/src/errors/MissingField.txt | 30 ---- dhall/src/errors/MissingHandler.txt | 32 ---- dhall/src/errors/MustCombineARecord.txt | 46 ------ dhall/src/errors/MustMergeARecord.txt | 43 ------ dhall/src/errors/MustMergeUnion.txt | 31 ---- dhall/src/errors/NoDependentLet.txt | 76 --------- dhall/src/errors/NoDependentTypes.txt | 31 ---- dhall/src/errors/NotAFunction.txt | 68 --------- dhall/src/errors/NotARecord.txt | 48 ------ dhall/src/errors/TypeMismatch.txt | 117 -------------- dhall/src/errors/UnboundVariable.txt | 97 ------------ dhall/src/errors/Untyped.txt | 117 -------------- dhall/src/errors/UnusedHandler.txt | 32 ---- dhall/src/lib.rs | 1 - dhall/src/phase/binary.rs | 17 ++- dhall/src/phase/mod.rs | 8 +- dhall/src/phase/resolve.rs | 11 +- dhall/src/phase/typecheck.rs | 114 ++------------ dhall/src/traits/dynamic_type.rs | 4 +- 76 files changed, 1961 insertions(+), 1953 deletions(-) delete mode 100644 dhall/src/error.rs create mode 100644 dhall/src/error/mod.rs create mode 100644 dhall/src/error/text/AnnotMismatch.txt create mode 100644 dhall/src/error/text/CantTextAppend.txt create mode 100644 dhall/src/error/text/DuplicateAlternative.txt create mode 100644 dhall/src/error/text/FieldCollision.txt create mode 100644 dhall/src/error/text/HandlerInputTypeMismatch.txt create mode 100644 dhall/src/error/text/HandlerNotAFunction.txt create mode 100644 dhall/src/error/text/HandlerOutputTypeMismatch.txt create mode 100644 dhall/src/error/text/IfBranchMismatch.txt create mode 100644 dhall/src/error/text/IfBranchMustBeTerm.txt create mode 100644 dhall/src/error/text/InvalidAlterantive.txt create mode 100644 dhall/src/error/text/InvalidAlterantiveType.txt create mode 100644 dhall/src/error/text/InvalidField.txt create mode 100644 dhall/src/error/text/InvalidFieldType.txt create mode 100644 dhall/src/error/text/InvalidInputType.txt create mode 100644 dhall/src/error/text/InvalidListElement.txt create mode 100644 dhall/src/error/text/InvalidListType.txt create mode 100644 dhall/src/error/text/InvalidOptionType.txt create mode 100644 dhall/src/error/text/InvalidOptionalElement.txt create mode 100644 dhall/src/error/text/InvalidOptionalLiteral.txt create mode 100644 dhall/src/error/text/InvalidOutputType.txt create mode 100644 dhall/src/error/text/InvalidPredicate.txt create mode 100644 dhall/src/error/text/MissingField.txt create mode 100644 dhall/src/error/text/MissingHandler.txt create mode 100644 dhall/src/error/text/MustCombineARecord.txt create mode 100644 dhall/src/error/text/MustMergeARecord.txt create mode 100644 dhall/src/error/text/MustMergeUnion.txt create mode 100644 dhall/src/error/text/NoDependentLet.txt create mode 100644 dhall/src/error/text/NoDependentTypes.txt create mode 100644 dhall/src/error/text/NotAFunction.txt create mode 100644 dhall/src/error/text/NotARecord.txt create mode 100644 dhall/src/error/text/TypeMismatch.txt create mode 100644 dhall/src/error/text/UnboundVariable.txt create mode 100644 dhall/src/error/text/Untyped.txt create mode 100644 dhall/src/error/text/UnusedHandler.txt delete mode 100644 dhall/src/errors/AnnotMismatch.txt delete mode 100644 dhall/src/errors/CantTextAppend.txt delete mode 100644 dhall/src/errors/DuplicateAlternative.txt delete mode 100644 dhall/src/errors/FieldCollision.txt delete mode 100644 dhall/src/errors/HandlerInputTypeMismatch.txt delete mode 100644 dhall/src/errors/HandlerNotAFunction.txt delete mode 100644 dhall/src/errors/HandlerOutputTypeMismatch.txt delete mode 100644 dhall/src/errors/IfBranchMismatch.txt delete mode 100644 dhall/src/errors/IfBranchMustBeTerm.txt delete mode 100644 dhall/src/errors/InvalidAlterantive.txt delete mode 100644 dhall/src/errors/InvalidAlterantiveType.txt delete mode 100644 dhall/src/errors/InvalidField.txt delete mode 100644 dhall/src/errors/InvalidFieldType.txt delete mode 100644 dhall/src/errors/InvalidInputType.txt delete mode 100644 dhall/src/errors/InvalidListElement.txt delete mode 100644 dhall/src/errors/InvalidListType.txt delete mode 100644 dhall/src/errors/InvalidOptionType.txt delete mode 100644 dhall/src/errors/InvalidOptionalElement.txt delete mode 100644 dhall/src/errors/InvalidOptionalLiteral.txt delete mode 100644 dhall/src/errors/InvalidOutputType.txt delete mode 100644 dhall/src/errors/InvalidPredicate.txt delete mode 100644 dhall/src/errors/MissingField.txt delete mode 100644 dhall/src/errors/MissingHandler.txt delete mode 100644 dhall/src/errors/MustCombineARecord.txt delete mode 100644 dhall/src/errors/MustMergeARecord.txt delete mode 100644 dhall/src/errors/MustMergeUnion.txt delete mode 100644 dhall/src/errors/NoDependentLet.txt delete mode 100644 dhall/src/errors/NoDependentTypes.txt delete mode 100644 dhall/src/errors/NotAFunction.txt delete mode 100644 dhall/src/errors/NotARecord.txt delete mode 100644 dhall/src/errors/TypeMismatch.txt delete mode 100644 dhall/src/errors/UnboundVariable.txt delete mode 100644 dhall/src/errors/Untyped.txt delete mode 100644 dhall/src/errors/UnusedHandler.txt diff --git a/dhall/src/error.rs b/dhall/src/error.rs deleted file mode 100644 index 8497a91..0000000 --- a/dhall/src/error.rs +++ /dev/null @@ -1,60 +0,0 @@ -use std::io::Error as IOError; - -use dhall_syntax::ParseError; - -use crate::phase::binary::DecodeError; -use crate::phase::resolve::ImportError; -use crate::phase::typecheck::TypeError; - -pub type Result = std::result::Result; - -#[derive(Debug)] -#[non_exhaustive] -pub enum Error { - IO(IOError), - Parse(ParseError), - Decode(DecodeError), - Resolve(ImportError), - Typecheck(TypeError), - Deserialize(String), -} - -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Error::IO(err) => write!(f, "{}", err), - Error::Parse(err) => write!(f, "{}", err), - Error::Decode(err) => write!(f, "{:?}", err), - Error::Resolve(err) => write!(f, "{:?}", err), - Error::Typecheck(err) => write!(f, "{:?}", err), - Error::Deserialize(err) => write!(f, "{}", err), - } - } -} - -impl std::error::Error for Error {} -impl From for Error { - fn from(err: IOError) -> Error { - Error::IO(err) - } -} -impl From for Error { - fn from(err: ParseError) -> Error { - Error::Parse(err) - } -} -impl From for Error { - fn from(err: DecodeError) -> Error { - Error::Decode(err) - } -} -impl From for Error { - fn from(err: ImportError) -> Error { - Error::Resolve(err) - } -} -impl From for Error { - fn from(err: TypeError) -> Error { - Error::Typecheck(err) - } -} diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs new file mode 100644 index 0000000..e70b9a9 --- /dev/null +++ b/dhall/src/error/mod.rs @@ -0,0 +1,169 @@ +use std::io::Error as IOError; + +use dhall_syntax::{BinOp, Import, Label, ParseError, V}; + +use crate::phase::resolve::ImportStack; +use crate::phase::typecheck::TypecheckContext; +use crate::phase::{Normalized, Type, Typed}; + +pub type Result = std::result::Result; + +#[derive(Debug)] +#[non_exhaustive] +pub enum Error { + IO(IOError), + Parse(ParseError), + Decode(DecodeError), + Resolve(ImportError), + Typecheck(TypeError), + Deserialize(String), +} + +#[derive(Debug)] +pub enum ImportError { + Recursive(Import, Box), + UnexpectedImport(Import), + ImportCycle(ImportStack, Import), +} + +#[derive(Debug)] +pub enum DecodeError { + CBORError(serde_cbor::error::Error), + WrongFormatError(String), +} + +/// A structured type error that includes context +#[derive(Debug)] +pub struct TypeError { + type_message: TypeMessage, + context: TypecheckContext, +} + +/// The specific type error +#[derive(Debug)] +pub(crate) enum TypeMessage { + UnboundVariable(V