From f992d368c1d84e0d10f0a174687b4707e145b657 Mon Sep 17 00:00:00 2001 From: Keanu Aloua Date: Tue, 22 Jul 2025 10:00:24 -0700 Subject: [PATCH 1/2] Replaced usages of renderErrorTemplate with renderFunctionErrorPage --- src/lib/functions/synchronous.ts | 4 ++-- src/lib/render-error-template.ts | 24 ------------------------ src/utils/proxy.ts | 4 ++-- 3 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 src/lib/render-error-template.ts diff --git a/src/lib/functions/synchronous.ts b/src/lib/functions/synchronous.ts index 56cf3e4f67c..43083f312a5 100644 --- a/src/lib/functions/synchronous.ts +++ b/src/lib/functions/synchronous.ts @@ -1,12 +1,12 @@ import { Buffer } from 'buffer' import { inspect } from 'util' +import { renderFunctionErrorPage } from '@netlify/dev-utils' import express from 'express' import { isReadableStream as baseIsReadableStream } from 'is-stream' import type { LambdaEvent } from 'lambda-local' import { chalk, logPadded, NETLIFYDEVERR } from '../../utils/command-helpers.js' -import renderErrorTemplate from '../render-error-template.js' import { warnIfAwsSdkError } from './utils.js' import type { InvocationError } from './netlify-function.js' @@ -161,7 +161,7 @@ const handleErr = async ( if (acceptsHtml) { response.setHeader('Content-Type', 'text/html') - response.end(await renderErrorTemplate(errorString, '../../src/lib/templates/function-error.html', 'function')) + response.end(await renderFunctionErrorPage(errorString, 'function')) } else { response.end(errorString) } diff --git a/src/lib/render-error-template.ts b/src/lib/render-error-template.ts deleted file mode 100644 index 0edb3d0401a..00000000000 --- a/src/lib/render-error-template.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { readFile } from 'fs/promises' -import { dirname, join } from 'path' -import { fileURLToPath } from 'url' - -// @ts-expect-error TS(7034) FIXME: Variable 'errorTemplateFile' implicitly has type '... Remove this comment to see the full error message -let errorTemplateFile -const dir = dirname(fileURLToPath(import.meta.url)) - -// @ts-expect-error TS(7006) FIXME: Parameter 'errString' implicitly has an 'any' type... Remove this comment to see the full error message -const renderErrorTemplate = async (errString, templatePath, functionType) => { - const errorDetailsRegex = //g - const functionTypeRegex = //g - - try { - // @ts-expect-error TS(7005) FIXME: Variable 'errorTemplateFile' implicitly has an 'an... Remove this comment to see the full error message - errorTemplateFile = errorTemplateFile || (await readFile(join(dir, templatePath), 'utf-8')) - - return errorTemplateFile.replace(errorDetailsRegex, errString).replace(functionTypeRegex, functionType) - } catch { - return errString - } -} - -export default renderErrorTemplate diff --git a/src/utils/proxy.ts b/src/utils/proxy.ts index 898485e6e4c..5aa29a27ea9 100644 --- a/src/utils/proxy.ts +++ b/src/utils/proxy.ts @@ -13,6 +13,7 @@ import url from 'url' import util from 'util' import zlib from 'zlib' +import { renderFunctionErrorPage } from '@netlify/dev-utils' import contentType from 'content-type' import cookie from 'cookie' import { getProperty } from 'dot-prop' @@ -37,7 +38,6 @@ import { fileExistsAsync, isFileAsync } from '../lib/fs.js' import { getFormHandler } from '../lib/functions/form-submissions-handler.js' import { DEFAULT_FUNCTION_URL_EXPRESSION } from '../lib/functions/registry.js' import { initializeProxy as initializeImageProxy, isImageRequest } from '../lib/images/proxy.js' -import renderErrorTemplate from '../lib/render-error-template.js' import { NETLIFYDEVLOG, NETLIFYDEVWARN, type NormalizedCachedConfigConfig, chalk, log } from './command-helpers.js' import createStreamPromise from './create-stream-promise.js' @@ -729,7 +729,7 @@ const initializeProxy = async function ({ const decompressedBody = await decompressResponseBody(responseBody, proxyRes.headers['content-encoding']) const formattedBody = formatEdgeFunctionError(decompressedBody, acceptsHtml) const errorResponse = acceptsHtml - ? await renderErrorTemplate(formattedBody, '../../src/lib/templates/function-error.html', 'edge function') + ? await renderFunctionErrorPage(formattedBody, 'edge function') : formattedBody const contentLength = Buffer.from(errorResponse, 'utf8').byteLength From d24456c49f8a4ccb81eb7d5b26648fdee241abca Mon Sep 17 00:00:00 2001 From: Keanu Aloua Date: Fri, 25 Jul 2025 11:20:13 -0700 Subject: [PATCH 2/2] refactor: remove function-error.html template --- src/lib/templates/function-error.html | 303 -------------------------- 1 file changed, 303 deletions(-) delete mode 100644 src/lib/templates/function-error.html diff --git a/src/lib/templates/function-error.html b/src/lib/templates/function-error.html deleted file mode 100644 index 479e8b13deb..00000000000 --- a/src/lib/templates/function-error.html +++ /dev/null @@ -1,303 +0,0 @@ - - - - - Invocation failed - - - - - - - -
-
-
-

- - This - - has crashed -

-

An unhandled error in the function code triggered the following message:

- -
- -
- - -
- -
- -