Skip to content

IncludeTag does not respect "ignore missing" #833

Open

Description

@aabeling

Please see my pull request #832.

Activity

  1. someth2say commented on Oct 19, 2023

    @someth2say

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions