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.

[Copied from CAS1.](ministryofjustice/hmpps-approved-premises-ui@8eed08b)
  • Loading branch information
patrickjfl committed Jan 16, 2024
1 parent 59c86eb commit 7be63e9
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 @@ -57,6 +57,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 7be63e9

Please sign in to comment.