We have internally implemented a throw_error tag, to make sure we make exhaustive "if" and "case" statements, and that we don't render invalid texts.
{%- if color == 'blue' -%}
bleu
{%- elsif color == 'green' -%}
vert
{%- elsif color == 'red' -%}
rouge
{%- else -%}
{% throw_error "unknown color: " | append: color %}
{%- endif -%}
class ThrowErrorTag extends Tag {
value: Value;
constructor(
tagToken: TagToken,
remainTokens: TopLevelToken[],
liquid: Liquid
) {
super(tagToken, remainTokens, liquid);
this.value = new Value(tagToken.args, liquid);
}
*render(ctx: Context): Generator<unknown, string, Context> {
const message = yield this.value.value(ctx);
throw new Error(`throw_error: ${message}`);
}
}
We like this feature, but would prefer some kind of exhaustive_if and exhaustive_case tag that automatically throws in the the "else" case. Would you be interested in a PR for this?
Or this could maybe be an exhaustiveIf, exhaustiveCase option in the Liquid constructor? Similar to lenientIf.
What do you think of the throw_error tag?
Or am I missing something and is there a way to do this already?
We have internally implemented a
throw_errortag, to make sure we make exhaustive "if" and "case" statements, and that we don't render invalid texts.{%- if color == 'blue' -%} bleu {%- elsif color == 'green' -%} vert {%- elsif color == 'red' -%} rouge {%- else -%} {% throw_error "unknown color: " | append: color %} {%- endif -%}We like this feature, but would prefer some kind of
exhaustive_ifandexhaustive_casetag that automatically throws in the the "else" case. Would you be interested in a PR for this?Or this could maybe be an
exhaustiveIf,exhaustiveCaseoption in the Liquid constructor? Similar tolenientIf.What do you think of the
throw_errortag?Or am I missing something and is there a way to do this already?