diff options
| author | Leedehai <18319900+Leedehai@users.noreply.github.com> | 2023-04-19 07:26:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-19 13:26:55 +0200 |
| commit | dc3017955a67e5509f6bc33cb9b4833806da4c22 (patch) | |
| tree | 364304f23268107cb0443fc0037a86bd4136d9ef /src/eval | |
| parent | e4b09d417e9bfc2c0011299272f33c6861e96a6f (diff) | |
Give more specific error messages (#881)
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/args.rs | 8 | ||||
| -rw-r--r-- | src/eval/scope.rs | 10 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/eval/args.rs b/src/eval/args.rs index aadd7d54..8617bd93 100644 --- a/src/eval/args.rs +++ b/src/eval/args.rs @@ -158,7 +158,13 @@ impl Args { /// argument. pub fn finish(self) -> SourceResult<()> { if let Some(arg) = self.items.first() { - bail!(arg.span, "unexpected argument"); + bail!( + arg.span, + match &arg.name { + Some(name) => eco_format!("unexpected argument: {}", name), + _ => eco_format!("unexpected argument"), + } + ) } Ok(()) } diff --git a/src/eval/scope.rs b/src/eval/scope.rs index e241cac5..f2207188 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::fmt::{self, Debug, Formatter}; use std::hash::Hash; -use ecow::EcoString; +use ecow::{eco_format, EcoString}; use super::{Library, Value}; use crate::diag::StrResult; @@ -42,7 +42,7 @@ impl<'a> Scopes<'a> { .chain(self.scopes.iter().rev()) .chain(self.base.map(|base| base.global.scope())) .find_map(|scope| scope.get(var)) - .ok_or("unknown variable")?) + .ok_or(eco_format!("unknown variable: {}", var))?) } /// Try to access a variable immutably in math. @@ -51,7 +51,7 @@ impl<'a> Scopes<'a> { .chain(self.scopes.iter().rev()) .chain(self.base.map(|base| base.math.scope())) .find_map(|scope| scope.get(var)) - .ok_or("unknown variable")?) + .ok_or(eco_format!("unknown variable: {}", var))?) } /// Try to access a variable mutably. @@ -61,8 +61,8 @@ impl<'a> Scopes<'a> { .find_map(|scope| scope.get_mut(var)) .ok_or_else(|| { match self.base.and_then(|base| base.global.scope().get(var)) { - Some(_) => "cannot mutate a constant", - _ => "unknown variable", + Some(_) => eco_format!("cannot mutate a constant: {}", var), + _ => eco_format!("unknown variable: {}", var), } })? } |
