Propel rocketboost.rs

Missing variable

A template can use a variable that the handler did not provide. When that happens, Propel stops rendering the page and returns an error. Propel is strict on purpose: a name that is missing from the context is a bug, and it should not quietly print nothing.

What causes it

The view below uses $not_in_context, but the context it is rendered with has no field of that name.

{{ $not_in_context }}

The context it is rendered with

Each view has a Rust struct that holds its data. The handler builds it, and this one has no fields:

#[derive(Serialize)]
pub struct NoFields {}

The handler passes it to the view. This is the route for this page:

PropelView::render("errors.missing", &Page::new("/errors/missing", Article {
    title: "Missing variable".into(),
}))

What you see

In a development build, the page shows an error page with the message and a hint. The message names the variable and the view:

undefined variable `not_in_context` in `errors.missing`
The debug error page for a missing variable, with the message undefined variable not_in_context
The debug page for this error, as it appears in a development build.

This page is a debug-only demo, and its route is absent in a release build. A release build compiles only the views the app lists in build.rs, and this one is not listed, so the browser never sees this error in release. In release, a render error on a compiled view is a generic 500, and the details go to the log.

How to fix it

There are two ways. Add the field to the context and fill it in the handler, or correct the name in the view. Here is the first:

#[derive(Serialize)]
pub struct Greeting {
    pub not_in_context: String,
}
PropelView::render("errors.missing", &Greeting {
    not_in_context: "Hello".into(),
})

Missing values that are allowed

A field that exists but is empty is not an error. A null value prints nothing, but a field of a null value is an error, so guard it with @if. See control flow.