Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncludeTag does not respect "ignore missing" #833

Open
aabeling opened this issue Feb 26, 2022 · 1 comment
Open

IncludeTag does not respect "ignore missing" #833

aabeling opened this issue Feb 26, 2022 · 1 comment

Comments

@aabeling
Copy link

Please see my pull request #832.

@someth2say
Copy link

someth2say commented Oct 19, 2023

Just in case it can help anyone, I workaround this limitation by registering a new include tag that ignores the exception:

    private static class IncludeTag extends com.hubspot.jinjava.lib.tag.IncludeTag implements Tag {

        @Override
        public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) {
            try {
                return super.interpret(tagNode,interpreter);
            } catch (InterpretException e) {
                if ( ignoreMissing(tagNode) && e.getCause() instanceof com.hubspot.jinjava.loader.ResourceNotFoundException) {
                    return "";
                }
                throw e;
            }
        }

        private boolean ignoreMissing(TagNode tagNode) {
            HelperStringTokenizer helper = new HelperStringTokenizer(tagNode.getHelpers());
            List<String> all = helper.allTokens();
            return (all.contains("ignore") && all.indexOf("missing") == all.indexOf("ignore") + 1);
        }
    }

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

No branches or pull requests

2 participants