home ~ projects ~ socials

Better minijinja Error Messages

```cargo
[dependencies]
minijinja = { version= "2.0.1", features = ["debug", "loader"] }
```

use minijinja::{Environment, context};

fn main() {
    let mut env = Environment::new();
    env.set_debug(true);
    env.add_template_owned(
        "hello", "{% include 'asdf' %}".to_string()
    ).unwrap();
    let template = env.get_template("hello").unwrap();
    match template.render(context!(name => "World")) {
      Ok(output) => println!("{}", output),
      Err(err) => {
          eprintln!("Could not render template: {:#}", err);

// this is how to get just the extra stuff
// println!("xxxxxxxx{}xxxxx", err.display_debug_info());


/*
        this is from the docs, but didn't do anything for me
          let mut err = &err as &dyn std::error::Error;
          while let Some(next_err) = err.source() {
              eprintln!();
              eprintln!("caused by: {:#}", next_err);
              err = next_err;
          }
          */

      }
    }
}
Output:
Could not render template: template not found: tried to include non-existing template "asdf" (in hello:1)
------------------------------------ hello ------------------------------------
   1 > {% include 'asdf' %}
     i    ^^^^^^^^^^^^^^ template not found
~~~~~~~~~~~~~~~~~~~~~~~~~~~
No referenced variables
-------------------------------------------------------------------------------
-- end of line --