Skip to content

Commit

Permalink
Allow full error trace in Nunjucks
Browse files Browse the repository at this point in the history
When a global function in a template throws an error, we don’t see the
full trace of the error, which makes diagnosing issues really hard.

This makes use of the [undocumented dev argument](mozilla/nunjucks#1430)
which allows us to see the cause of the error in our logs and in Sentry.

I’ve had to extend the nunjucks types to allow for this option to be
set, as it’s not in the type definition in `DefinitelyTyped`. However,
I’ve [opened a PR to add this](DefinitelyTyped/DefinitelyTyped#63968)
  • Loading branch information
pezholio committed Jan 18, 2023
1 parent 4092c55 commit 8eed08b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/@types/nunjucks/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {}

declare module 'nunjucks' {
export interface ConfigureOptions {
dev?: boolean | undefined
}
}
1 change: 1 addition & 0 deletions server/utils/nunjucksSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function nunjucksSetup(app: express.Express, path: pathModule.Pla
{
autoescape: true,
express: app,
dev: true, // This is set to true to allow us to see the full stacktrace from errors in global functions, otherwise it gets swallowed and tricky to see in logs
},
)

Expand Down

0 comments on commit 8eed08b

Please sign in to comment.