From 7b9ea5dabb346316d1fb072aefdd11ea4225f90f Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 23 Dec 2022 19:50:14 +0100 Subject: [PATCH] Add links to the user-manual to errors, when applicable. --- crates/aiken-lang/src/tipo/error.rs | 102 +++++++++++++++++++++++++++- crates/aiken-project/src/error.rs | 21 ++++++ 2 files changed, 120 insertions(+), 3 deletions(-) diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index 51924d3f..4d9bbeb9 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -97,7 +97,7 @@ pub enum Error { given: usize, }, - #[error("I realized that a given 'when clause' is non-exhaustive.\n")] + #[error("I realized that a given 'when/is' expression is non-exhaustive.\n")] NotExhaustivePatternMatch { location: Span, unmatched: Vec, @@ -1098,7 +1098,7 @@ impl Diagnostic for Error { match self { Self::DuplicateArgument { locations, .. } => Some(Box::new( locations - .into_iter() + .iter() .map(|l| LabeledSpan::new_with_span(None, *l)), )), Self::DuplicateConstName { @@ -1125,7 +1125,7 @@ impl Diagnostic for Error { )), Self::DuplicateField { locations, .. } => Some(Box::new( locations - .into_iter() + .iter() .map(|l| LabeledSpan::new_with_span(None, *l)), )), Self::DuplicateName { @@ -1261,6 +1261,102 @@ impl Diagnostic for Error { )), } } + + fn url<'a>(&'a self) -> Option> { + match self { + Self::DuplicateArgument { .. } => None, + Self::DuplicateConstName { .. } => None, + Self::DuplicateImport { .. } => None, + Self::DuplicateField { .. } => None, + Self::DuplicateName { .. } => None, + Self::DuplicateTypeName { .. } => None, + Self::IncorrectFieldsArity { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/custom-types", + )), + Self::IncorrectFunctionCallArity { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/functions#named-functions", + )), + Self::IncorrectPatternArity { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#matching", + )), + Self::IncorrectNumClausePatterns { .. } => None, + Self::IncorrectTupleArity { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#destructuring", + )), + Self::IncorrectTypeArity { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/custom-types#generics", + )), + Self::NotExhaustivePatternMatch { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#matching", + )), + Self::NotFn { .. } => None, + Self::KeywordInModuleName { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/modules" + )), + Self::NonLocalClauseGuardVariable { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#checking-equality-and-ordering-in-patterns" + )), + Self::PositionalArgumentAfterLabeled { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/functions#labeled-arguments" + )), + Self::PrivateTypeLeak { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/modules" + )), + Self::RecordAccessUnknownType { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/variables-and-constants#type-annotations" + )), + Self::RecordUpdateInvalidConstructor { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/custom-types#record-updates" + )), + Self::ReservedModuleName { .. } => None, + Self::UnexpectedLabeledArg { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/functions#labeled-arguments" + )), + Self::UnexpectedLabeledArgInPattern { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/custom-types#named-accessors" + )), + Self::UnexpectedTypeHole { .. } => None, + Self::UnknownLabels { .. } => None, + Self::UnknownModule { .. } => None, + Self::UnknownModuleField { .. } => None, + Self::UnknownModuleValue { .. } => None, + Self::UnknownModuleType { .. } => None, + Self::UnknownRecordField { .. } => None, + Self::UnknownType { .. } => None, + Self::UnknownVariable { .. } => None, + Self::UnknownTypeConstructor { .. } => None, + Self::UnnecessarySpreadOperator { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#destructuring" + )), + Self::UpdateMultiConstructorType { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/custom-types#record-updates" + )), + Self::CouldNotUnify { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/primitive-types" + )), + Self::ExtraVarInAlternativePattern { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#alternative-clause-patterns" + )), + Self::MissingVarInAlternativePattern { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#alternative-clause-patterns" + )), + Self::DuplicateVarInPattern { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/control-flow#alternative-clause-patterns" + )), + Self::CyclicTypeDefinitions { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/custom-types#type-aliases" + )), + Self::RecursiveType { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/variables-and-constants#type-annotations" + )), + Self::NotATuple { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/primitive-types#tuples" + )), + Self::TupleIndexOutOfBound { .. } => Some(Box::new( + "https://aiken-lang.org/language-tour/primitive-types#tuples" + )), + } + } } #[derive(Debug, PartialEq, Clone, thiserror::Error, Diagnostic)] diff --git a/crates/aiken-project/src/error.rs b/crates/aiken-project/src/error.rs index 3f65a5b5..9e887ddd 100644 --- a/crates/aiken-project/src/error.rs +++ b/crates/aiken-project/src/error.rs @@ -368,6 +368,27 @@ impl Diagnostic for Error { Error::JoinError(_) => None, } } + + fn url<'a>(&'a self) -> Option> { + match self { + Error::DuplicateModule { .. } => None, + Error::FileIo { .. } => None, + Error::ImportCycle { .. } => None, + Error::List { .. } => None, + Error::Parse { .. } => None, + Error::Type { error, .. } => error.url(), + Error::StandardIo(_) => None, + Error::MissingManifest { .. } => None, + Error::TomlLoading { .. } => None, + Error::Format { .. } => None, + Error::ValidatorMustReturnBool { .. } => None, + Error::WrongValidatorArity { .. } => None, + Error::TestFailure { .. } => None, + Error::Http { .. } => None, + Error::ZipExtract { .. } => None, + Error::JoinError { .. } => None, + } + } } #[derive(thiserror::Error)]