Skip to content

Commit

Permalink
feat: improve error message on unknown key/action (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
rszyma authored Nov 11, 2023
1 parent 1d49a7b commit 53c3462
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion parser/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,16 @@ fn parse_action_atom(ac_span: &Spanned<String>, s: &ParsedState) -> Result<&'sta
let (mut keys, unparsed_str) = parse_mod_prefix(ac)?;
keys.push(
str_to_oscode(unparsed_str)
.ok_or_else(|| anyhow!("Unknown key/action/variable: {ac:?}"))?
.ok_or_else(|| {
// check aliases
if s.aliases.contains_key(ac) {
anyhow!("Unknown key/action: {ac}. If you meant to use an alias, prefix it with '@' symbol: @{ac}")
} else if s.vars.contains_key(ac) {
anyhow!("Unknown key/action: {ac}. If you meant to use a variable, prefix it with '$' symbol: ${ac}")
} else {
anyhow!("Unknown key/action: {ac}")
}
})?
.into(),
);
Ok(s.a.sref(Action::MultipleKeyCodes(s.a.sref(s.a.sref_vec(keys)))))
Expand Down

0 comments on commit 53c3462

Please sign in to comment.