Skip to content

Commit 09214b3

Browse files
committed
fix(tegg): preserve load error caller path
1 parent 0ebb28e commit 09214b3

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

tegg/core/loader/src/LoaderUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class LoaderUtil {
8787
try {
8888
exports = await import(filePath);
8989
} catch (e: unknown) {
90-
throw createLoadError(filePath, e);
90+
throw createLoadError(originalFilePath, e);
9191
}
9292
}
9393
const clazzList: EggProtoImplClass[] = [];

tegg/core/loader/test/Loader.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ describe('core/loader/test/Loader.test.ts', () => {
9292
},
9393
);
9494
});
95+
96+
it('should keep the caller path when wrapping dynamic import errors on win32', async () => {
97+
const platform = Object.getOwnPropertyDescriptor(process, 'platform');
98+
const missingFile = path.join(__dirname, './fixtures/modules/module-for-loader/MissingService.ts');
99+
globalThis.__EGG_BUNDLE_MODULE_LOADER__ = () => undefined;
100+
101+
Object.defineProperty(process, 'platform', {
102+
value: 'win32',
103+
});
104+
try {
105+
await assert.rejects(
106+
async () => {
107+
await LoaderUtil.loadFile(missingFile);
108+
},
109+
(err: Error) => {
110+
assert(err.message.startsWith(`[tegg/loader] load ${missingFile} failed:`));
111+
return true;
112+
},
113+
);
114+
} finally {
115+
Object.defineProperty(process, 'platform', platform!);
116+
}
117+
});
95118
});
96119

97120
describe('file has tsc error', () => {

0 commit comments

Comments
 (0)