From dfb69b833d92f039b1723128a7954b40e5e7f36d Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 17 Aug 2023 19:43:40 +0800 Subject: [PATCH 1/5] fix: do not print duplicate error message --- packages/vite/src/node/plugins/importAnalysis.ts | 4 +++- packages/vite/src/node/plugins/optimizedDeps.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index c33cd519fb4da7..333df27a6ca97f 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -57,6 +57,7 @@ import { getDepsOptimizer, optimizedDepNeedsInterop } from '../optimizer' import { ERR_CLOSED_SERVER } from '../server/pluginContainer' import { checkPublicFile, urlRE } from './asset' import { + ERR_EISDIR, ERR_OUTDATED_OPTIMIZED_DEP, throwOutdatedRequest, } from './optimizedDeps' @@ -663,7 +664,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { server.transformRequest(url, { ssr }).catch((e) => { if ( e?.code === ERR_OUTDATED_OPTIMIZED_DEP || - e?.code === ERR_CLOSED_SERVER + e?.code === ERR_CLOSED_SERVER || + e?.code === ERR_EISDIR ) { // these are expected errors return diff --git a/packages/vite/src/node/plugins/optimizedDeps.ts b/packages/vite/src/node/plugins/optimizedDeps.ts index 7bb1e040517320..8a69df58109874 100644 --- a/packages/vite/src/node/plugins/optimizedDeps.ts +++ b/packages/vite/src/node/plugins/optimizedDeps.ts @@ -9,6 +9,7 @@ import { getDepsOptimizer, optimizedDepInfoFromFile } from '../optimizer' export const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR' export const ERR_OUTDATED_OPTIMIZED_DEP = 'ERR_OUTDATED_OPTIMIZED_DEP' +export const ERR_EISDIR = 'EISDIR' const debug = createDebugger('vite:optimize-deps') From 37739fd818777baf1ecad87727df178fdd582863 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 6 Oct 2023 18:02:03 +0800 Subject: [PATCH 2/5] fix: update error message --- packages/vite/src/node/plugins/importAnalysis.ts | 4 +--- packages/vite/src/node/plugins/optimizedDeps.ts | 1 - packages/vite/src/node/server/transformRequest.ts | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index a1b95a312c304c..dbfc8b9347b1d2 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -55,7 +55,6 @@ import { getDepsOptimizer, optimizedDepNeedsInterop } from '../optimizer' import { ERR_CLOSED_SERVER } from '../server/pluginContainer' import { checkPublicFile, urlRE } from './asset' import { - ERR_EISDIR, ERR_OUTDATED_OPTIMIZED_DEP, throwOutdatedRequest, } from './optimizedDeps' @@ -627,8 +626,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { server.transformRequest(url, { ssr }).catch((e) => { if ( e?.code === ERR_OUTDATED_OPTIMIZED_DEP || - e?.code === ERR_CLOSED_SERVER || - e?.code === ERR_EISDIR + e?.code === ERR_CLOSED_SERVER ) { // these are expected errors return diff --git a/packages/vite/src/node/plugins/optimizedDeps.ts b/packages/vite/src/node/plugins/optimizedDeps.ts index 8a69df58109874..7bb1e040517320 100644 --- a/packages/vite/src/node/plugins/optimizedDeps.ts +++ b/packages/vite/src/node/plugins/optimizedDeps.ts @@ -9,7 +9,6 @@ import { getDepsOptimizer, optimizedDepInfoFromFile } from '../optimizer' export const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR' export const ERR_OUTDATED_OPTIMIZED_DEP = 'ERR_OUTDATED_OPTIMIZED_DEP' -export const ERR_EISDIR = 'EISDIR' const debug = createDebugger('vite:optimize-deps') diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index cbc0b768f70198..653dbc094370f5 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -206,7 +206,7 @@ async function loadAndTransform( } catch (e) { if (e.code !== 'ENOENT') { if (e.code === 'EISDIR') { - e.message = `${e.message} ${file}` + e.message = `Pre-transform ${e.message} ${file}` } throw e } From dead93f686a3c1e10e3979b303126fa731bd16e9 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 9 Oct 2023 16:02:00 +0800 Subject: [PATCH 3/5] fix: update message --- packages/vite/src/node/plugins/importAnalysis.ts | 4 +++- packages/vite/src/node/server/middlewares/indexHtml.ts | 2 +- packages/vite/src/node/server/transformRequest.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index dbfc8b9347b1d2..e1f306f9c9ddf8 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -632,7 +632,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { return } // Unexpected error, log the issue but avoid an unhandled exception - config.logger.error(e.message, { error: e }) + config.logger.error(`Pre-transform error: ${e.message}`, { + error: e, + }) }) } } else if (!importer.startsWith(withTrailingSlash(clientDir))) { diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 678c09fc7c029c..f55c5c6a2abc73 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -360,6 +360,6 @@ function preTransformRequest(server: ViteDevServer, url: string, base: string) { return } // Unexpected error, log the issue but avoid an unhandled exception - server.config.logger.error(e.message) + server.config.logger.error(`Pre-transform error: ${e.message}`) }) } diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index 653dbc094370f5..cbc0b768f70198 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -206,7 +206,7 @@ async function loadAndTransform( } catch (e) { if (e.code !== 'ENOENT') { if (e.code === 'EISDIR') { - e.message = `Pre-transform ${e.message} ${file}` + e.message = `${e.message} ${file}` } throw e } From c5b47987b8a7ced83e9fabe3199cfa65c6593624 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 9 Oct 2023 16:21:10 +0800 Subject: [PATCH 4/5] feat: error message add timestamp option --- packages/vite/src/node/plugins/importAnalysis.ts | 1 + packages/vite/src/node/server/middlewares/indexHtml.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index e1f306f9c9ddf8..87b5d1e33cf01c 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -634,6 +634,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // Unexpected error, log the issue but avoid an unhandled exception config.logger.error(`Pre-transform error: ${e.message}`, { error: e, + timestamp: true, }) }) } diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index f55c5c6a2abc73..af743cdcd8a1f4 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -360,6 +360,8 @@ function preTransformRequest(server: ViteDevServer, url: string, base: string) { return } // Unexpected error, log the issue but avoid an unhandled exception - server.config.logger.error(`Pre-transform error: ${e.message}`) + server.config.logger.error(`Pre-transform error: ${e.message}`, { + timestamp: true, + }) }) } From 6715718acb255d74f439b768abc01a0cf3821400 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Mon, 9 Oct 2023 18:03:47 +0800 Subject: [PATCH 5/5] Update packages/vite/src/node/server/middlewares/indexHtml.ts Co-authored-by: patak --- packages/vite/src/node/server/middlewares/indexHtml.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index af743cdcd8a1f4..c9d9228a0d79ef 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -361,6 +361,7 @@ function preTransformRequest(server: ViteDevServer, url: string, base: string) { } // Unexpected error, log the issue but avoid an unhandled exception server.config.logger.error(`Pre-transform error: ${e.message}`, { + error: e, timestamp: true, }) })