Skip to content

Commit

Permalink
Improved error handling to catch invalid use of filters in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaddalena committed Oct 14, 2022
1 parent b5bb8cd commit 82c9dd5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ghostwriter/modules/reportwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from docx.oxml.shared import OxmlElement, qn
from docx.shared import Inches, Pt, RGBColor
from docxtpl import DocxTemplate, RichText
from jinja2.exceptions import TemplateSyntaxError, UndefinedError
from jinja2.exceptions import TemplateRuntimeError, TemplateSyntaxError, UndefinedError
from pptx import Presentation
from pptx.dml.color import RGBColor as PptxRGBColor
from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE, PP_ALIGN
Expand Down Expand Up @@ -2346,6 +2346,18 @@ def lint_docx(self):
"result": "failed",
"errors": [f"Invalid filter value: {error.message}"],
}
except TypeError as error:
logger.error("Invalid value provided to filter or expression: %s", error)
results = {
"result": "failed",
"errors": [f"Invalid value provided to filter or expression: {error}"],
}
except TemplateRuntimeError as error:
logger.error("Invalid filter or expression: %s", error)
results = {
"result": "failed",
"errors": [f"Invalid filter or expression: {error}"],
}
except Exception:
logger.exception("Template failed rendering")
results = {
Expand Down Expand Up @@ -2392,6 +2404,18 @@ def lint_pptx(self):
"result": "failed",
"errors": ["Template file is not a PowerPoint presentation"],
}
except TypeError as error:
logger.error("Invalid value provided to filter or expression: %s", error)
results = {
"result": "failed",
"errors": [f"Invalid value provided to filter or expression: {error}"],
}
except TemplateRuntimeError as error:
logger.error("Invalid filter or expression: %s", error)
results = {
"result": "failed",
"errors": [f"Invalid filter or expression: {error}"],
}
except Exception:
logger.exception("Template failed rendering")
results = {
Expand Down

0 comments on commit 82c9dd5

Please sign in to comment.