Skip to content

Conversation

hlounent
Copy link

@hlounent hlounent commented Apr 10, 2019

Add support for throwing an exception if a key referenced by a template is not found. This is useful for clients that want to ensure templates and the related input data structure match and want to handle potential mismatches as failures.

P.S. I also rebased the patches against torbjoernk/mstch branch develop and pushed to the branch torbjoernk/report-missing-keys as some of the other open pull requests have been merged there.

The new test case verifies the current behavior that no exceptions are
thrown if a key mentioned in a template is not found.

The Catch2 TEST_CASE macro was used directly instead of the MSTCH_TEST
or other macros because this test case does not verify output of the
mstch::render with a given input, what MSTCH_TEST and friends are for.

Signed-off-by: Hannu Lounento <[email protected]>
Throwing an exception enables clients to detect failures to render
template completely due to missing keys. This is useful in cases where
clients expect templates and the data structure to always match and
treat missing keys as failures.

Define a custom exception to enable clients to identify the specific
type of the error.

Signed-off-by: Hannu Lounento <[email protected]>
@danobi
Copy link

danobi commented May 7, 2019

Ignoring the code (although it looks fine to me), I'm +1 on this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants