Skip to content

Opt-in errors when a parameter is missing, or an unused parameter is passed #40

Description

@ysangkok

I noticed that missing parameters are rendered as empty strings.

>>> ashes_env.register_source('hello', 'Hello, {name}!')
<Template name='hello'>
>>> ashes_env.render('hello', {})
'Hello, !'

It would be nice if it was possible to opt-in to errors. My use case is that I want to test that I am not passing the wrong parameters for a template.

Thanks in advance, I like the library.

Activity

  1. mahmoud commented on Feb 1, 2021

    @mahmoud
    Owner

    Hey there! Glad you like ashes. This isn't possible with the library right this second, but I've got some ideas. Most revolve around this line here.

    Would a log statement work? Or are you trying to raise a full-blown error?

  2. ysangkok commented on Feb 1, 2021

    @ysangkok
    Author

    I mainly just want to use it for testing, I want to make sure that my dataclasses have the right fields, which I turn into dictionaries and pass into ashes. So it could be a boolean, or it could be a logging context-manager that I could inspect for warnings (and get a bool). Or it could be an optional kwarg. I don't mind too much, as long as I can make my test fail if the dataclass doesn't match the template.

  3. jvanasco commented on Feb 1, 2021

    @jvanasco
    Contributor

    Years ago, I started work on extending ashes to track the utilized fields. I never got it to recurse correctly though.

    The use-case for me was to build a model of what ashes used in the template. This would allow us to write tests where we could ensure we pass the correct data into ashes, but also optimize the data structure. Our app renders the templates in the cloud with ashes, or in a browser/app with JavaScript; being able to strip unused fields from the JavaScript payload was a big goal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions