Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -851,17 +851,15 @@ public HostCapacityVO call(HostCapacityVO cap) {
long deltaMemory = ratioMgr.calculateMemoryByRatio(hostUuid, memory);
long availMemory = cap.getAvailableMemory() + deltaMemory;
if (availMemory > cap.getTotalMemory()) {
throw new CloudRuntimeException(
String.format("invalid memory capacity of host[uuid:%s]," +
" available memory[%s] is greater than total memory[%s]." +
" Available Memory before is [%s], Delta Memory is [%s].",
hostUuid,
new DecimalFormat(",###").format(availMemory),
new DecimalFormat(",###").format(cap.getTotalMemory()),
new DecimalFormat(",###").format(cap.getAvailableMemory()),
new DecimalFormat(",###").format(deltaMemory)
)
);
logger.warn(String.format("memory capacity overflow on host[uuid:%s]," +
" available memory[%s] > total memory[%s], clamping to total." +
" Available Memory before is [%s], Delta Memory is [%s].",
hostUuid,
new DecimalFormat(",###").format(availMemory),
new DecimalFormat(",###").format(cap.getTotalMemory()),
new DecimalFormat(",###").format(cap.getAvailableMemory()),
new DecimalFormat(",###").format(deltaMemory)));
availMemory = cap.getTotalMemory();
}

cap.setAvailableMemory(availMemory);
Expand Down
4 changes: 2 additions & 2 deletions plugin/ldap/src/main/java/org/zstack/ldap/LdapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,10 @@ public LdapServerVO getLdapServer() {
sq.add(LdapServerVO_.scope, SimpleQuery.Op.EQ, scope);
List<LdapServerVO> ldapServers = sq.list();
if (ldapServers.isEmpty()) {
throw new CloudRuntimeException("No LDAP/AD server record in database.");
throw new OperationFailureException(operr(ORG_ZSTACK_LDAP_10020, "No LDAP/AD server record in database."));
}
if (ldapServers.size() > 1) {
throw new CloudRuntimeException("More than one LDAP/AD server record in database.");
throw new OperationFailureException(operr(ORG_ZSTACK_LDAP_10021, "More than one LDAP/AD server record in database."));
}
return ldapServers.get(0);
}
Expand Down
2 changes: 1 addition & 1 deletion search/src/main/java/org/zstack/query/QueryFacadeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private void handle(APIQueryMessage msg) {
} catch (OperationFailureException of) {
throw of;
} catch (Exception e) {
throw new CloudRuntimeException(e);
throw new OperationFailureException(inerr("failed to query: %s", e.getMessage()));
}
Comment on lines 378 to 382
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.

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,10 @@ public class CloudOperationsErrorCode {

public static final String ORG_ZSTACK_LDAP_10019 = "ORG_ZSTACK_LDAP_10019";

public static final String ORG_ZSTACK_LDAP_10020 = "ORG_ZSTACK_LDAP_10020";

public static final String ORG_ZSTACK_LDAP_10021 = "ORG_ZSTACK_LDAP_10021";

public static final String ORG_ZSTACK_IMAGE_10000 = "ORG_ZSTACK_IMAGE_10000";

public static final String ORG_ZSTACK_IMAGE_10001 = "ORG_ZSTACK_IMAGE_10001";
Expand Down Expand Up @@ -10652,6 +10656,8 @@ public class CloudOperationsErrorCode {

public static final String ORG_ZSTACK_PREMIUM_EXTERNALSERVICE_PROMETHEUS_10013 = "ORG_ZSTACK_PREMIUM_EXTERNALSERVICE_PROMETHEUS_10013";

public static final String ORG_ZSTACK_PREMIUM_EXTERNALSERVICE_PROMETHEUS_10014 = "ORG_ZSTACK_PREMIUM_EXTERNALSERVICE_PROMETHEUS_10014";

public static final String ORG_ZSTACK_AI_CONTAINER_10000 = "ORG_ZSTACK_AI_CONTAINER_10000";

public static final String ORG_ZSTACK_AI_CONTAINER_10001 = "ORG_ZSTACK_AI_CONTAINER_10001";
Expand Down