完善错误处理

This commit is contained in:
Pan Qiancheng 2025-05-08 12:59:28 +08:00
parent a51dac512c
commit 4f15fe79d0
2 changed files with 16 additions and 6 deletions

View File

@ -235,5 +235,5 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"version": "2.0.0"
"version": "2.0.1"
}

View File

@ -138,6 +138,19 @@ function anaEntitiesUsingDomain(): EntityDict {
const pHome = pathConfig.projectHome;
const cwd = process.cwd();
try {
// 先判断${pHome}/node_modules/oak-domain/lib/compiler/schemalBuilder.js是否存在
const schemaFilePath = path.join(
pHome,
'node_modules',
'oak-domain',
'lib',
'compiler',
'schemalBuilder.js'
);
if (!fs.existsSync(schemaFilePath)) {
throw new Error('oak-domain未安装或版本不匹配');
}
// 这里需要设置一下当前目录,防止找不到模块
process.chdir(pHome);
const { analyzeEntities, getAnalizedSchema, translateLocaleObject, constructAttributes, getProjectionKeys } =
require(`${pHome}/node_modules/oak-domain/lib/compiler/schemalBuilder`);
@ -251,14 +264,11 @@ export const analyzeOakAppDomain = async (
setLoadingEntities(true);
isAnalyzing = true;
try {
const newEntityDict = anaEntitiesUsingDomain();
// 更新 entityDictCache
Object.keys(newEntityDict).forEach((key) => {
entityDictCache[key] = newEntityDict[key];
});
if (enableCache) {
// 写入缓存
fs.writeFile(
@ -276,8 +286,8 @@ export const analyzeOakAppDomain = async (
} catch (error) {
console.log('分析过程中发生错误:', error);
// 删除缓存的目录,便于下一次分析
vscode.window.showErrorMessage(`分析过程中发生错误`);
fs.unlinkSync(pathConfig.cachePath);
vscode.window.showErrorMessage(`分析过程中发生错误: ${(error as Error).message}`);
fs.unlinkSync(cacheFile);
} finally {
isAnalyzing = false;
setLoadingEntities(false);