<fix>[multi]: batch fix CRE quality issues#3379
Conversation
- LdapUtil: CRE to OperationFailureException - QueryFacadeImpl: CRE to OperationFailureException - HostAllocatorManagerImpl: CRE to warn + clamp - CloudOperationsErrorCode: add LDAP/PROMETHEUS codes Resolves: ZSTAC-81334 Change-Id: Iab947b0476e9174d5a61baa095847b521b1f59fa
概览本次更改涉及四个文件的异常处理和错误代码管理的调整。主要包括将特定场景的异常类型从 CloudRuntimeException 改为 OperationFailureException,以及对内存容量溢出情况的处理方式进行优化。 变更内容
代码审查工作量估计🎯 2 (简单) | ⏱️ ~12 分钟 诗句
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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.javaComment |
There was a problem hiding this comment.
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.
| } catch (OperationFailureException of) { | ||
| throw of; | ||
| } catch (Exception e) { | ||
| throw new CloudRuntimeException(e); | ||
| throw new OperationFailureException(inerr("failed to query: %s", e.getMessage())); | ||
| } |
There was a problem hiding this comment.
🧩 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 -20Repository: 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 -40Repository: 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 javaRepository: 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 -40Repository: 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 javaRepository: 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.javaRepository: 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.
Summary
Batch fix for CloudRuntimeException (CRE) issues found by periodic quality scripts.
Resolves
ZSTAC-81334
Testing
sync from gitlab !9214