VGalaxies commented on code in PR #3029:
URL: https://github.com/apache/hugegraph/pull/3029#discussion_r3371506698
##########
hugegraph-pd/hg-pd-service/pom.xml:
##########
@@ -175,6 +175,7 @@
<mainClass>
org.apache.hugegraph.pd.boot.HugePDServer
</mainClass>
+ <classifier>exec</classifier>
Review Comment:
**High: PD executable jar is no longer the artifact used by the
distribution**
`hugegraph-pd/hg-pd-service/pom.xml:178`
**Evidence**
- The new `<classifier>exec</classifier>` makes Spring Boot attach the
repackaged executable jar as a classified artifact, while
`hugegraph-pd/hg-pd-dist/src/assembly/descriptor/server-assembly.xml:52`
includes the unclassified `hg-pd-service` dependency and
`start-hugegraph-pd.sh:172-176` runs `${LIB}/hg-pd-service-*.jar` with `java
-jar`.
**Impact**
- The PD dist will package/run the plain unclassified jar instead of the
executable Spring Boot jar, so packaged PD startup can fail or run the wrong
artifact.
**Requested fix**
- Either remove the classifier so the main artifact remains executable, or
update `hg-pd-dist` to depend on and include the `exec` classifier explicitly
and make the startup glob select only that jar.
##########
hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/controller/exceptionhandlers/StoreExceptionHandler.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.store.node.controller.exceptionhandlers;
+
+import org.apache.hugegraph.rest.response.ApiResponse;
+import org.apache.hugegraph.store.util.HgStoreException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@RestControllerAdvice
+public class StoreExceptionHandler {
+
+ private static final Logger logger =
Logger.getLogger(StoreExceptionHandler.class.getName());
+
+ @ExceptionHandler(HgStoreException.class)
+ public ResponseEntity<ApiResponse<Object>>
handleHgStoreException(HgStoreException exception) {
+ int errorCode = exception.getCode();
+ HttpStatus status;
+
+ if (errorCode >= 1200 && errorCode < 1300) {
+ status = HttpStatus.INTERNAL_SERVER_ERROR;
+ logger.log(Level.SEVERE,
+ "Critical error at database (Code " + errorCode + "): "
+ exception.getMessage(), exception);
+ } else if (errorCode >= 1000 && errorCode < 1200) {
+ status = HttpStatus.BAD_REQUEST;
+
+ logger.log(Level.WARNING,
+ "Validation failed at store (Code " + errorCode + "): "
+ exception.getMessage(), exception);
+ } else {
+ status = HttpStatus.INTERNAL_SERVER_ERROR;
+
+ logger.log(Level.SEVERE,
+ "Unexpected error at store (Code " + errorCode + "): "
+ exception.getMessage(), exception);
+ }
+
+ ApiResponse<Object> apiResponse = new ApiResponse<>(
+ status.value(),
Review Comment:
**Medium: Store response body drops the `HgStoreException` code**
`hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/controller/exceptionhandlers/StoreExceptionHandler.java:57`
**Evidence**
- The handler reads `exception.getCode()` at line 37, but constructs
`ApiResponse` with `status.value()` at line 57. Store exceptions define
machine-readable codes such as `1001` and `1201` in
`HgStoreException.java:23-40`.
**Impact**
- Clients receive only HTTP codes like `400` or `500` in the unified `code`
field and lose the store-specific error code needed to distinguish validation,
closed-store, RocksDB, PD, and metric failures.
**Requested fix**
- Use `errorCode` for `ApiResponse.code` and keep the HTTP status only in
the `ResponseEntity` status.
##########
hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/exceptionshandler/PDExceptionMapper.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.pd.rest.exceptionshandler;
+
+import org.apache.hugegraph.pd.common.PDException;
+import org.apache.hugegraph.rest.response.ApiResponse;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@RestControllerAdvice
+public class PDExceptionMapper {
+
+ private static final Logger logger =
LogManager.getLogger(PDExceptionMapper.class);
+
+ @ExceptionHandler(PDException.class)
+ public ResponseEntity<ApiResponse<Object>> toResponse(PDException
exception) {
+
+ logger.error(exception.getMessage(), exception);
+
+ HttpStatus status = resolveStatus(exception.getErrorCode());
+ String reasonPhrase = status.getReasonPhrase();
+
+ ApiResponse<Object> apiResponse = new ApiResponse<>(
+ exception.getErrorCode(),
+ exception.getMessage(),
+ null,
+ reasonPhrase);
+
+ return ResponseEntity
+ .status(status)
+ .body(apiResponse);
+
+ }
+
+ private HttpStatus resolveStatus(int code) {
+ try {
+ // Tenta mapear códigos HTTP exatos (ex: 400, 404, 500)
+ return HttpStatus.valueOf(code);
+ } catch (IllegalArgumentException e) {
+ // Se falhar (ex: 4001), extraímos o primeiro dígito para
descobrir a família do erro
+ String codeStr = String.valueOf(code);
+
+ if (codeStr.startsWith("4")) {
+ return HttpStatus.BAD_REQUEST; // Erros de cliente -> 400
+ }
+
+ // Tudo que for da família 5000 ou não reconhecido vira Erro de
Servidor -> 500
+ return HttpStatus.INTERNAL_SERVER_ERROR;
Review Comment:
**Medium: Real PD error codes are mapped to HTTP 500**
`hugegraph-pd/hg-pd-service/src/main/java/org/apache/hugegraph/pd/rest/exceptionshandler/PDExceptionMapper.java:67`
**Evidence**
- `resolveStatus()` only treats exact HTTP codes or codes starting with `4`
as client errors; actual PD codes include `STORE_ID_NOT_EXIST = 101`,
`NOT_FOUND = 103`, and `PD_UNREACHABLE = 104` in
`hugegraph-pd/hg-pd-grpc/src/main/proto/pdpb.proto:134-139`, so those become
`500`.
**Impact**
- Uncaught domain errors such as not-found/store-not-found are reported as
server failures, which breaks HTTP semantics and can mislead clients, retries,
and monitoring.
**Requested fix**
- Map the existing `Pdpb.ErrorType` values explicitly to appropriate HTTP
statuses, or preserve the previous REST status behavior while only changing the
response body format.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]