From 44187725d649cc2e4e7b78f7671f35161117b43f Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 22 Apr 2022 14:04:20 +0800 Subject: [PATCH] chore: improve error log --- packages/uni-cli-i18n/locales/en.json | 2 +- packages/uni-cli-i18n/locales/zh_CN.json | 2 +- packages/uni-cli-shared/lib/json.js | 11 +++-------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/uni-cli-i18n/locales/en.json b/packages/uni-cli-i18n/locales/en.json index 2dfce1c30..be37499fc 100644 --- a/packages/uni-cli-i18n/locales/en.json +++ b/packages/uni-cli-i18n/locales/en.json @@ -7,7 +7,7 @@ "platform": "platform", "plugin": "plugin", "performingHotReload": "Performing hot reload...", - "cliShared.parsingFailed": "Parsing failed", + "cliShared.parseJsonFailed": "Parsing failed", "cliShared.doesNotExist": "does not exist", "cliShared.pagesJsonError": "pages.json page configuration error, has been ignored, see {{0}}", "cliShared.requireReturnJsonObject": "require return a json object", diff --git a/packages/uni-cli-i18n/locales/zh_CN.json b/packages/uni-cli-i18n/locales/zh_CN.json index 8f5dda838..c48eb8b62 100644 --- a/packages/uni-cli-i18n/locales/zh_CN.json +++ b/packages/uni-cli-i18n/locales/zh_CN.json @@ -7,7 +7,7 @@ "platform": "平台", "plugin": "插件", "performingHotReload": "正在差量编译...", - "cliShared.parsingFailed": "解析失败", + "cliShared.parseJsonFailed": "解析失败,不符合 json 规范", "cliShared.doesNotExist": "不存在", "cliShared.pagesJsonError": "pages.json 页面配置错误,已被忽略,查看文档: {{0}}", "cliShared.requireReturnJsonObject": "必须返回一个 json 对象", diff --git a/packages/uni-cli-shared/lib/json.js b/packages/uni-cli-shared/lib/json.js index 810173e88..09afa37fe 100644 --- a/packages/uni-cli-shared/lib/json.js +++ b/packages/uni-cli-shared/lib/json.js @@ -14,12 +14,7 @@ function parseJson (content, preprocess = false) { type: jsPreprocessOptions.type }) } - - try { - content = JSON.parse(stripJsonComments(content)) - } catch (e) { - throw new Error('uni-app-compiler: ' + e.message) - } + content = JSON.parse(stripJsonComments(content)) } content = JSON.stringify(content) @@ -37,11 +32,11 @@ function getJson (jsonFileName, preprocess = false) { try { return parseJson(fs.readFileSync(jsonFilePath, 'utf8'), preprocess) } catch (e) { - console.error(jsonFileName + uniI18n.__('cliShared.parsingFailed')) + throw new Error(jsonFileName + uniI18n.__('cliShared.parseJsonFailed') + '\n' + e.message) } } module.exports = { getJson, parseJson -} +} -- GitLab