Skip to content

Conversation

Sunrisea
Copy link
Contributor

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

Fix the bug :when publish config is limited,the ConfigController.publishConfig return success

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

Copy link

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

Copy link

lingma-agents bot commented May 24, 2025

修复配置控制器在发布配置受限时错误响应码的缺陷

变更文件

文件路径 变更说明
config/​src/​main/​java/​com/​alibaba/​nacos/​config/​server/​controller/​ConfigController.java 在publishConfig方法中添加try-catch块捕获NacosException,通过response.setStatus(e.getErrCode())设置错误状态码,并将返回逻辑从直接调用改为通过publishResult变量控制

时序图

sequenceDiagram
    participant CC as ConfigController
    participant COS as ConfigOperationService
    CC->>COS: 调用publishConfig(configForm...)
    opt 发生异常时
        COS-->>CC: 抛出NacosException
        CC->>Response: 设置response.setStatus(e.getErrCode())
    else 正常执行时
        COS-->>CC: 返回publishResult
    end
    CC-->>Response: 返回最终结果
Loading

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 代码评审报告

📋 评审意见详情

💡 单文件建议

✅ 未发现需要特别关注的代码问题。

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 异常处理模式与架构设计不一致

当前修改在ConfigController的publishConfig方法中直接处理NacosException并设置响应码,这可能与项目现有的全局异常处理机制产生冲突。若项目采用统一的异常处理器(如Spring的@ExceptionHandler或全局错误处理类)来统一管理异常响应,这种分散式处理会破坏架构一致性。此改动可能导致不同端点的异常响应格式不统一,增加维护复杂度。

📌 关键代码:

try {
    publishResult = configOperationService.publishConfig(configForm, configRequestInfo, encryptedDataKeyFinal);
} catch (NacosException e) {
    response.setStatus(e.getErrCode());
}

⚠️ 潜在风险: 1. 引发异常处理逻辑分散,后续维护时难以统一调整响应格式
2. 可能与现有全局异常处理器重复处理导致状态码冲突
3. 新增的异常处理分支未被现有测试覆盖,存在遗漏场景风险

🔍 2. HTTP状态码映射的业务一致性风险

直接使用NacosException的errCode作为HTTP状态码可能存在语义不匹配。业务错误码(如配置校验失败)与HTTP标准状态码(如400/403/500)的映射关系未明确处理,可能导致客户端误解错误类型。需要确认errCode到HTTP状态码的转换逻辑是否符合系统统一规范。

📌 关键代码:

response.setStatus(e.getErrCode());

⚠️ 潜在风险: 1. 返回的HTTP状态码可能不符合RESTful规范
2. 客户端可能无法正确识别错误类型进行容错处理
3. 需要与前后端契约文档保持一致,否则影响系统集成

🔍 3. 未处理的异常传播链风险

当publishConfig方法返回false时,HTTP响应状态码可能未正确设置。当前代码在catch块设置状态码后仍返回publishResult,但若异常未被捕获(如抛出非NacosException类型),可能导致状态码未设置而直接返回默认值。需要确保所有异常路径都有明确的状态码处理。

⚠️ 潜在风险: 1. 某些异常场景可能返回错误的200状态码
2. 未预期的异常类型可能导致系统级错误码缺失
3. 需补充针对非NacosException的异常处理逻辑

🔍 4. 测试覆盖范围不足

当前修改新增了异常处理分支,但未观察到对应的测试用例补充。需要确保新增的异常处理路径(如NacosException触发的状态码设置)和正常返回路径都有独立测试覆盖,特别是边界情况如无效CAS校验、权限不足等场景。

⚠️ 潜在风险: 1. 新增逻辑可能因缺乏测试而存在隐藏缺陷
2. 回归测试时可能遗漏异常分支验证
3. 需补充配置发布失败场景的端到端测试用例


💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

@wuyfee
Copy link

wuyfee commented May 24, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.27%. Comparing base (ee59f98) to head (e06905f).
Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
...cos/config/server/controller/ConfigController.java 66.66% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             develop   #13432      +/-   ##
=============================================
- Coverage      70.27%   70.27%   -0.01%     
  Complexity     11728    11728              
=============================================
  Files           1601     1601              
  Lines          51098    51106       +8     
  Branches        5152     5152              
=============================================
+ Hits           35910    35913       +3     
- Misses         12756    12761       +5     
  Partials        2432     2432              
Files with missing lines Coverage Δ
...cos/config/server/controller/ConfigController.java 66.59% <66.66%> (-0.08%) ⬇️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee59f98...e06905f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KomachiSion KomachiSion added this to the 3.0.2 milestone May 26, 2025
@KomachiSion KomachiSion added kind/bug Category issues or prs related to bug. area/Config labels May 26, 2025
@KomachiSion KomachiSion merged commit b47f978 into alibaba:develop May 26, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Config kind/bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants