Skip to content

Commit

Permalink
feat(errors): Report available tags blocks
Browse files Browse the repository at this point in the history
Fixes #183
  • Loading branch information
epage committed Dec 12, 2018
1 parent d8d6f66 commit 04e486a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions liquid-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ travis-ci = { repository = "cobalt-org/liquid-rust" }
appveyor = { repository = "johannhof/liquid-rust" }

[dependencies]
itertools = "0.7.0"
pest = "2.0"
pest_derive = "2.0"

Expand Down
2 changes: 1 addition & 1 deletion liquid-compiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate liquid_error;
extern crate liquid_interpreter;
extern crate liquid_value;

extern crate itertools;
extern crate pest;
#[macro_use]
extern crate pest_derive;
Expand Down
12 changes: 11 additions & 1 deletion liquid-compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,17 @@ impl<'a> Tag<'a> {
},
position,
);
Err(convert_pest_error(pest_error))
let mut all_tags: Vec<_> = options.tags.plugin_names().collect();
all_tags.sort_unstable();
let all_tags = itertools::join(all_tags, ", ");
let mut all_blocks: Vec<_> = options.blocks.plugin_names().collect();
all_blocks.sort_unstable();
let all_blocks = itertools::join(all_blocks, ", ");
let error = convert_pest_error(pest_error)
.context("requested", name.to_owned())
.context("available tags", all_tags)
.context("available blocks", all_blocks);
Err(error)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion liquid-interpreter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ impl<'g> Context<'g> {
f
})
.ok_or_else(|| {
let available = itertools::join(self.filters.plugin_names(), ", ");
let mut available: Vec<_> = self.filters.plugin_names().collect();
available.sort_unstable();
let available = itertools::join(available, ", ");
Error::with_msg("Unknown filter")
.context("requested filter", name.to_owned())
.context("available filters", available)
Expand Down

0 comments on commit 04e486a

Please sign in to comment.