merge cherry-pick-mr-258-1757916556680-auto into master

优化module.json引用错误资源的报错信息

Created-by: leeduo
Commit-by: liduo
Merged-by: openharmony_ci
Description: 1. 优化module.json引用错误资源的报错信息
---
### 一、内容说明(相关的Issue)

优化module.json引用错误资源的报错信息

### 二、建议测试周期和提测地址  
  建议测试完成时间:xxxx.xx.xx  
  投产上线时间:xxxx.xx.xx  
  提测地址:CI环境/压测环境  
  测试账号:  

### 三、变更内容
  * 3.1 关联PR列表

  * 3.2 数据库和部署说明  
    1. 常规更新 
    2. 重启unicorn
    3. 重启sidekiq
    4. 迁移任务:是否有迁移任务,没有写 "无"
    5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无"

  * 3.4 其他技术优化内容(做了什么,变更了什么)
    不涉及


  * 3.5 废弃通知(什么字段、方法弃用?)
    不涉及


  * 3.6  后向不兼容变更(是否有无法向后兼容的变更?)
    不涉及

  
### 四、研发自测点(自测哪些?冒烟用例全部自测?)
  自测测试结论:


### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
  检查点:不涉及

  接口测试:不涉及

  性能测试:不涉及

  并发测试:不涉及

  其他:不涉及

### L0新增用例自检结果
- [ ] 是,有新增L0用例,且完成自检
- [x] 否


See merge request: openharmony/developtools_global_resource_tool!262
This commit is contained in:
openharmony_ci
2025-09-15 19:10:37 +08:00
3 changed files with 75 additions and 24 deletions
+11
View File
@@ -134,6 +134,17 @@ struct MoreInfo {
std::string en;
};
struct ExtSolution {
std::string fileName;
std::string solution;
};
struct FaqInfo {
std::string cn;
std::string en;
std::vector<ExtSolution> extSolutions;
};
class ErrorInfo {
public:
uint32_t code_;
+9
View File
@@ -8,6 +8,15 @@
"code": 11201001,
"cn": "https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-compiling-and-building-181",
"en": "https://developer.huawei.com/consumer/en/doc/harmonyos-faqs/faqs-compiling-and-building-181"
},
{
"code": 11211120,
"extSolutions": [
{
"fileName": "module.json",
"solution": "Check whether the hvigorfile.ts in the project root directory or the module.json5 file in the module directory references undefined resources."
}
]
}
]
}
+55 -24
View File
@@ -537,8 +537,8 @@ const std::string LOCALE_CMD_LINUX = "locale";
const std::string LOCALE_CMD_MAC = "defaults read -globalDomain AppleLocale";
const std::string LOCALE_CN = "zh_CN";
std::map<uint32_t, MoreInfo> faqInfos;
MoreInfo defaultMoreInfo = {};
std::map<uint32_t, FaqInfo> faqInfos;
FaqInfo defaultMoreInfo = {};
Language osLanguage = Language::EN;
bool IsValidCmd(const std::string &cmd)
@@ -733,7 +733,26 @@ Language GetOsLanguage()
return Language::CN;
}
void GetMoreInfo(cJSON *node, MoreInfo &info)
void GetExtSolutions(cJSON *node, FaqInfo &info)
{
if (!node || !cJSON_IsArray(node)) {
return;
}
for (cJSON *subNode = node->child; subNode; subNode = subNode->next) {
ExtSolution solution{};
cJSON *fileNameNode = cJSON_GetObjectItem(subNode, "fileName");
if (fileNameNode && cJSON_IsString(fileNameNode)) {
solution.fileName = fileNameNode->valuestring;
}
cJSON *solutionNode = cJSON_GetObjectItem(subNode, "solution");
if (solutionNode && cJSON_IsString(solutionNode)) {
solution.solution = solutionNode->valuestring;
}
info.extSolutions.push_back(solution);
}
}
void GetFaqInfo(cJSON *node, FaqInfo &info)
{
if (node && cJSON_IsObject(node)) {
cJSON *cn = cJSON_GetObjectItem(node, "cn");
@@ -744,6 +763,7 @@ void GetMoreInfo(cJSON *node, MoreInfo &info)
if (en && cJSON_IsString(en)) {
info.en = en->valuestring;
}
GetExtSolutions(cJSON_GetObjectItem(node, "extSolutions"), info);
}
}
@@ -760,20 +780,20 @@ void InitFaq(const std::string &restoolPath)
return;
}
cJSON *defaultNode = cJSON_GetObjectItem(root, "default");
GetMoreInfo(defaultNode, defaultMoreInfo);
GetFaqInfo(defaultNode, defaultMoreInfo);
cJSON *faqsNode = cJSON_GetObjectItem(root, "faqs");
if (!faqsNode || !cJSON_IsArray(faqsNode) || cJSON_GetArraySize(faqsNode) == 0) {
cJSON_Delete(root);
return;
}
for (cJSON *infoNode = faqsNode->child; infoNode; infoNode = faqsNode->next) {
for (cJSON *infoNode = faqsNode->child; infoNode; infoNode = infoNode->next) {
cJSON *codeNode = cJSON_GetObjectItem(infoNode, "code");
if (!codeNode || !cJSON_IsNumber(codeNode)) {
continue;
}
uint32_t code = static_cast<uint32_t>(codeNode->valueint);
MoreInfo info = {};
GetMoreInfo(infoNode, info);
FaqInfo info = {};
GetFaqInfo(infoNode, info);
faqInfos[code] = info;
}
cJSON_Delete(root);
@@ -788,7 +808,7 @@ ErrorInfo GetError(const uint32_t &errCode)
}
auto faq = faqInfos.find(errCode);
if (faq != faqInfos.end()) {
error.moreInfo_ = faq->second;
error.moreInfo_ = { faq->second.cn, faq->second.en };
}
return error;
}
@@ -808,27 +828,38 @@ void PrintError(const ErrorInfo &error)
errMsg.append(" At file: ").append(error.position_);
}
errMsg.append("\n");
if (!error.solutions_.empty()) {
errMsg.append("* Try the following:").append("\n");
for (const auto &solution : error.solutions_) { errMsg.append(" > ").append(solution).append("\n"); }
std::string moreInfo;
if (osLanguage == Language::CN) {
if (!error.moreInfo_.cn.empty()) {
moreInfo = error.moreInfo_.cn;
} else {
moreInfo = defaultMoreInfo.cn;
if (error.solutions_.empty()) {
std::cerr << errMsg;
return;
}
errMsg.append("* Try the following:").append("\n");
for (const auto &solution : error.solutions_) { errMsg.append(" > ").append(solution).append("\n"); }
auto faq = faqInfos.find(error.code_);
if (faq != faqInfos.end()) {
std::vector<ExtSolution> extSolutions = faq->second.extSolutions;
for (const auto &solution : extSolutions) {
if (FileEntry(error.position_).GetFilePath().GetFilename() == solution.fileName) {
errMsg.append(" > ").append(solution.solution).append("\n");
}
}
}
std::string moreInfo;
if (osLanguage == Language::CN) {
if (!error.moreInfo_.cn.empty()) {
moreInfo = error.moreInfo_.cn;
} else {
if (!error.moreInfo_.en.empty()) {
moreInfo = error.moreInfo_.en;
} else {
moreInfo = defaultMoreInfo.en;
}
moreInfo = defaultMoreInfo.cn;
}
if (!moreInfo.empty()) {
errMsg.append("> More info: ").append(moreInfo).append("\n");
} else {
if (!error.moreInfo_.en.empty()) {
moreInfo = error.moreInfo_.en;
} else {
moreInfo = defaultMoreInfo.en;
}
}
if (!moreInfo.empty()) {
errMsg.append(" > More info: ").append(moreInfo).append("\n");
}
std::cerr << errMsg;
}
} // namespace Restool