Skip to content

Comments

<fix>[multi]: batch fix CRE quality issues#3379

Closed
ZStack-Robot wants to merge 1 commit into5.5.6from
sync/ye.zou/fix/cre-batch-quality-issues@@2
Closed

<fix>[multi]: batch fix CRE quality issues#3379
ZStack-Robot wants to merge 1 commit into5.5.6from
sync/ye.zou/fix/cre-batch-quality-issues@@2

Conversation

@ZStack-Robot
Copy link
Collaborator

Summary

Batch fix for CloudRuntimeException (CRE) issues found by periodic quality scripts.

  • LdapUtil: CRE to OperationFailureException
  • QueryFacadeImpl: CRE to OperationFailureException
  • HostAllocatorManagerImpl: CRE to warn + clamp
  • CloudOperationsErrorCode: add LDAP/PROMETHEUS codes

Resolves

ZSTAC-81334

Testing

  • Compile verified
  • CRE → OperationFailureException conversion ensures proper error propagation instead of unhandled crashes

sync from gitlab !9214

- LdapUtil: CRE to OperationFailureException
- QueryFacadeImpl: CRE to OperationFailureException
- HostAllocatorManagerImpl: CRE to warn + clamp
- CloudOperationsErrorCode: add LDAP/PROMETHEUS codes

Resolves: ZSTAC-81334

Change-Id: Iab947b0476e9174d5a61baa095847b521b1f59fa
@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

概览

本次更改涉及四个文件的异常处理和错误代码管理的调整。主要包括将特定场景的异常类型从 CloudRuntimeException 改为 OperationFailureException,以及对内存容量溢出情况的处理方式进行优化。

变更内容

文件组 / 文件路径 变更摘要
异常处理标准化
plugin/ldap/src/main/java/org/zstack/ldap/LdapUtil.java, search/src/main/java/org/zstack/query/QueryFacadeImpl.java
将 CloudRuntimeException 替换为 OperationFailureException,并添加特定的错误代码引用。LDAP 模块增加了针对缺失或重复记录的具体错误码(ORG_ZSTACK_LDAP_10020、ORG_ZSTACK_LDAP_10021)。
内存容量处理
compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
修改内存容量溢出处理逻辑,从抛出异常改为记录警告并将可用内存限制到总内存值,避免异常中断流程。
错误代码常量
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
新增 Prometheus 外部服务错误代码常量 ORG_ZSTACK_PREMIUM_EXTERNALSERVICE_PROMETHEUS_10014。

代码审查工作量估计

🎯 2 (简单) | ⏱️ ~12 分钟

诗句

🐰 跳呀跳,异常改妙
CloudRuntime 轻轻退场
OperationFailure 来报到
错误码整整齐齐排
内存溢出不再慌张~ 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题完全符合指定格式 [multi]: batch fix CRE quality issues,准确总结了主要变更内容:修复CloudRuntimeException质量问题。
Description check ✅ Passed 描述与变更集相关,详细列出了四个文件中的具体修改内容,包括异常类型替换和错误代码添加等,清晰表达了PR的目的和内容。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/ye.zou/fix/cre-batch-quality-issues@@2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.5)
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@search/src/main/java/org/zstack/query/QueryFacadeImpl.java`:
- Around line 378-382: The catch-all Exception block in QueryFacadeImpl throws
an OperationFailureException using Platform.inerr with the wrong parameter
order; update the call to pass the error-code constant first (e.g.,
ORG_ZSTACK_QUERY_10013) then the format string and args so it matches
Platform.inerr(String globalErrorCode, String fmt, Object...); replace the
current inerr("failed to query: %s", e.getMessage()) with
inerr(ORG_ZSTACK_QUERY_10013, "failed to query: %s", e.getMessage()) to align
with other usages and fix the exception construction.

Comment on lines 378 to 382
} catch (OperationFailureException of) {
throw of;
} catch (Exception e) {
throw new CloudRuntimeException(e);
throw new OperationFailureException(inerr("failed to query: %s", e.getMessage()));
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine the actual file and surrounding context
find . -type f -name "QueryFacadeImpl.java" | head -1 | xargs cat -n | sed -n '370,390p'

Repository: MatheMatrix/zstack

Length of output: 1029


🏁 Script executed:

# Search for Platform.inerr method definitions
fd -a "Platform.java" --type f | xargs rg -A 5 "public.*inerr\("

Repository: MatheMatrix/zstack

Length of output: 779


🏁 Script executed:

# Look for error code definitions related to query
fd -a "ErrorCode.java" --type f | xargs rg -i "ORG_ZSTACK_QUERY" | head -20

Repository: MatheMatrix/zstack

Length of output: 3721


🏁 Script executed:

# Search for similar query error handling patterns in the codebase
rg -A 3 "catch.*Exception.*query" --type java | head -40

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# Check the error code definitions and their messages
rg -B 2 -A 2 "ORG_ZSTACK_QUERY_10000|ORG_ZSTACK_QUERY_10001|ORG_ZSTACK_QUERY_10002" --type java

Repository: MatheMatrix/zstack

Length of output: 1213


🏁 Script executed:

# Look for how similar exception handling is done in other query/search related code
rg -B 2 -A 2 "new OperationFailureException.*inerr" search/ --type java | head -40

Repository: MatheMatrix/zstack

Length of output: 2218


🏁 Script executed:

# Check if QueryFacadeImpl uses any specific error codes elsewhere
rg -B 2 -A 2 "ORG_ZSTACK_QUERY" search/src/main/java/org/zstack/query/ --type java

Repository: MatheMatrix/zstack

Length of output: 6204


🏁 Script executed:

# Examine method signature and how inerr should be called correctly
rg -B 1 -A 10 "public static ErrorCode inerr" core/src/main/java/org/zstack/core/Platform.java

Repository: MatheMatrix/zstack

Length of output: 596


修复 inerr() 调用的参数顺序错误

第 381 行的代码错误地调用了 inerr() 方法。根据 Platform.inerr() 的方法签名 public static ErrorCode inerr(String globalErrorCode, String fmt, Object...args),第一个参数必须是错误码常量(如 ORG_ZSTACK_QUERY_10013),而不是格式化字符串。

建议改为:

throw new OperationFailureException(inerr(ORG_ZSTACK_QUERY_10013, "failed to query: %s", e.getMessage()));

这样才能与其他相同方式的异常处理保持一致(如第 248 行的用法)。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@search/src/main/java/org/zstack/query/QueryFacadeImpl.java` around lines 378
- 382, The catch-all Exception block in QueryFacadeImpl throws an
OperationFailureException using Platform.inerr with the wrong parameter order;
update the call to pass the error-code constant first (e.g.,
ORG_ZSTACK_QUERY_10013) then the format string and args so it matches
Platform.inerr(String globalErrorCode, String fmt, Object...); replace the
current inerr("failed to query: %s", e.getMessage()) with
inerr(ORG_ZSTACK_QUERY_10013, "failed to query: %s", e.getMessage()) to align
with other usages and fix the exception construction.

@zstack-robot-2 zstack-robot-2 deleted the sync/ye.zou/fix/cre-batch-quality-issues@@2 branch February 20, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants