package com.hubspot.jinjava.interpret;

/**
 * Container exception thrown when fatal errors are encountered while rendering a template.
 *
 * @author jstehler
 */
public class FatalTemplateErrorsException extends InterpretException {
  private static final long serialVersionUID = 1L;

  private final String template;
  private final Iterable<TemplateError> errors;

  public FatalTemplateErrorsException(String template, Iterable<TemplateError> errors) {
    super(generateMessage(errors));
    this.template = template;
    this.errors = errors;
  }

  private static String generateMessage(Iterable<TemplateError> errors) {
    StringBuilder msg = new StringBuilder();

    for (TemplateError error : errors) {
      msg.append(error.toString()).append('\n');
    }

    return msg.toString();
  }

  public String getTemplate() {
    return template;
  }

  public Iterable<TemplateError> getErrors() {
    return errors;
  }

}

@@ -33,16 +33,75 @@
 rpret;%0A%0A
+import org.apache.commons.lang3.exception.ExceptionUtils;%0A%0A
 /**%0A * C
@@ -815,16 +815,152 @@
 d('%5Cn');
+%0A%0A      if (error.getException() != null) %7B%0A        msg.append(ExceptionUtils.getStackTrace(error.getException())).append('%5Cn');%0A      %7D
 %0A    %7D%0A%0A

include exception stack trace in FatalTemplateErrorsException message