From 04e486a87781c6cb46c8ca0da56f7a310eb567cb Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 12 Dec 2018 12:19:27 -0700 Subject: [PATCH] feat(errors): Report available tags blocks Fixes #183 --- liquid-compiler/Cargo.toml | 1 + liquid-compiler/src/lib.rs | 2 +- liquid-compiler/src/parser.rs | 12 +++++++++++- liquid-interpreter/src/context.rs | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/liquid-compiler/Cargo.toml b/liquid-compiler/Cargo.toml index 00bca00a0..aaefb0265 100644 --- a/liquid-compiler/Cargo.toml +++ b/liquid-compiler/Cargo.toml @@ -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" diff --git a/liquid-compiler/src/lib.rs b/liquid-compiler/src/lib.rs index c0b9b2fcb..32bd10767 100644 --- a/liquid-compiler/src/lib.rs +++ b/liquid-compiler/src/lib.rs @@ -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; diff --git a/liquid-compiler/src/parser.rs b/liquid-compiler/src/parser.rs index 52a7c2589..552ec9154 100644 --- a/liquid-compiler/src/parser.rs +++ b/liquid-compiler/src/parser.rs @@ -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) } } } diff --git a/liquid-interpreter/src/context.rs b/liquid-interpreter/src/context.rs index 1c1be27f5..b6e6a4635 100644 --- a/liquid-interpreter/src/context.rs +++ b/liquid-interpreter/src/context.rs @@ -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)