Skip to content

[Improvement] Add Originating Exception Message When An TemplateSyntaxException Is Thrown As A Result Of Function Invocation Error #752

Description

@bhreinb

When an invocation to a function happens which fails it is caught as either a
IllegalAccessException or InvocationTargetException within jinjava.de.odysseus.el.tree.impl.ast#eval
which is re-thrown as an ELException .

This ELException exception gets caught in class com.hubspot.jinjava.el.ExpressionResolver#resolveExpression which ultimately gets caught again and gets re-thrown as a TemplateSyntaxException via line 188

      } else {
        interpreter.addError(
          TemplateError.fromException(
            new TemplateSyntaxException(
              expression,
              e.getMessage(),
              interpreter.getLineNumber(),
              e
            )
          )
        );
      }

It would be nice if the TemplateSyntaxException included the original exception message that caused the problem perhaps. Namely

      } else {
        interpreter.addError(
          TemplateError.fromException(
            new TemplateSyntaxException(
              expression,
              String.format("%s%nOriginal Failure:%n%s" e.getMessage(), e.getCause().getMessage())
              interpreter.getLineNumber(),
              e
            )
          )
        );
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions