From 5004f4b67db937f152be3b9a8f700a0f9e48d9bd Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 7 Feb 2023 13:41:48 -0500 Subject: [PATCH] recover from Liquid rendering errors in release notes (#34484) Co-authored-by: Rachael Sewell --- lib/render-with-fallback.js | 2 +- .../contextualizers/ghes-release-notes.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/render-with-fallback.js b/lib/render-with-fallback.js index 75d52a0ace..8973931f5d 100644 --- a/lib/render-with-fallback.js +++ b/lib/render-with-fallback.js @@ -60,7 +60,7 @@ export async function executeWithFallback(context, callable, fallback) { try { return await callable(context) } catch (error) { - if (isLiquidError(error)) { + if (isLiquidError(error) && context.currentLanguage !== 'en') { const enContext = Object.assign({}, context, { currentLanguage: 'en' }) return await fallback(enContext) } diff --git a/middleware/contextualizers/ghes-release-notes.js b/middleware/contextualizers/ghes-release-notes.js index 6edf54974b..e3c38fa627 100644 --- a/middleware/contextualizers/ghes-release-notes.js +++ b/middleware/contextualizers/ghes-release-notes.js @@ -1,5 +1,6 @@ import { formatReleases, renderPatchNotes } from '../../lib/release-notes-utils.js' import { all } from '../../lib/enterprise-server-releases.js' +import { executeWithFallback } from '../../lib/render-with-fallback.js' import { getReleaseNotes } from './get-release-notes.js' export default async function ghesReleaseNotesContext(req, res, next) { @@ -28,7 +29,21 @@ export default async function ghesReleaseNotesContext(req, res, next) { // Run the current release notes through the markdown rendering pipeline. // Returns the current release's patches array: [{version, patchVersion, intro, date, sections}] - req.context.ghesReleaseNotes = await renderPatchNotes(currentReleaseNotes, req.context) + req.context.ghesReleaseNotes = await executeWithFallback( + req.context, + () => renderPatchNotes(currentReleaseNotes, req.context), + (enContext) => { + // Something in the release notes ultimately caused a Liquid + // rendering error. Let's start over and gather the English release + // notes instead. + const ghesReleaseNotes = getReleaseNotes('enterprise-server', 'en') + enContext.ghesReleases = formatReleases(ghesReleaseNotes) + const currentReleaseNotes = enContext.ghesReleases.find( + (r) => r.version === requestedRelease + ).patches + return renderPatchNotes(currentReleaseNotes, enContext) + } + ) // GHES release notes on docs started with 2.20 but older release notes exist on enterprise.github.com. // So we want to use _all_ GHES versions when calculating next and previous releases.