sunng87 / handlebars-iron

Handlebars middleware for Iron web framework
MIT License
119 stars 20 forks source link

Improve Template errors reporting #53

Closed mrLSD closed 7 years ago

mrLSD commented 7 years ago

Currently, mistakes at the templates syntax really dangerous zone.

For example:

  let mut template = HandlebarsEngine::new();
  hbs.add(Box::new(DirectorySource::new(path, ".hbs")));
  if let Err(r) = hbs.reload() {
      ###  panic!("{:?}", r.description());
  }

And for example template with wrong helper name: mytemplate.hbs

<div>
    {{#myhelper 123}}{{/myhelper}}
</div>

Compilation successful. I tried run: thread 'main' panicked at '"TemplateError"', src/middleware/render.rs:50

I suggesting extremely improve error reporting, for example:

Template parse error:
    |> mytemplate.hbs 2:5
    |> {{#myhelper 123}}{{/myhelper}}
        --------------------------
Error: unsupported helper name.

Same for any other template errors.

My reasons:

sunng87 commented 7 years ago

After some investigation, I found this is because the description/display information of TemplateError is missing when nested in TemplateFileError. I'm going to fix this in handlebars side and include more information to the error data (sunng87/handlebars-rust#112)

sunng87 commented 7 years ago

Template error reporting received a few improvements in handlebars-rust 0.22. Please cargo update you handlebars-iron to latest release and use println!("{}", e) for detailed error information (Template name, line number, column number and error message). Both template error and render error are covered.