imbajin commented on code in PR #683:
URL: 
https://github.com/apache/incubator-hugegraph-toolchain/pull/683#discussion_r2464760826


##########
hugegraph-loader/src/main/java/org/apache/hugegraph/loader/HugeGraphLoader.java:
##########
@@ -109,42 +206,63 @@ public boolean load() {
             // Print load summary
             Printer.printSummary(this.context);
         } catch (Throwable t) {
+            this.context.occurredError();
+
+            if (t instanceof ServerException) {
+                ServerException e = (ServerException) t;
+                String logMessage =
+                        "Log ServerException: \n" + e.exception() + "\n";
+                if (e.trace() != null) {
+                    logMessage += StringUtils.join((List<String>) e.trace(),
+                                                   "\n");
+                }
+                LOG.warn(logMessage);
+            }
+
             RuntimeException e = LoadUtil.targetRuntimeException(t);
             Printer.printError("Failed to load", e);
-            if (this.context.options().testMode) {
-                throw e;
-            }
-        } finally {
-            this.stopThenShutdown();
+            LOG.error("Load failed with exception", e);
+
+            throw e;
         }
+
         return this.context.noError();
     }
 
+    public void shutdown() {
+        this.stopThenShutdown();
+    }
+
     private void clearAllDataIfNeeded() {
-        LoadOptions options = this.context.options();
         if (!options.clearAllData) {
             return;
         }
 
         int requestTimeout = options.timeout;
         options.timeout = options.clearTimeout;
         HugeClient client = HugeClientHolder.create(options);
-        String message = "I'm sure to delete all data";
-
-        LOG.info("Prepare to clear the data of graph '{}'", options.graph);
-        client.graphs().clearGraph(options.graph, message);
-        LOG.info("The graph '{}' has been cleared successfully", 
options.graph);
 
-        options.timeout = requestTimeout;
-        client.close();
+        try {
+            LOG.info("Prepare to clear the data of graph '{}'", options.graph);
+            client.graphs().clearGraph(options.graph, "I'm sure to delete all 
data");
+            LOG.info("The graph '{}' has been cleared successfully",
+                     options.graph);
+        } catch (Exception e) {
+            LOG.error("Failed to clear data for graph '{}': {}", 
options.graph, e.getMessage(), e);

Review Comment:
   🧹 **Minor: 日志级别不一致**
   
   在 `clearAllDataIfNeeded()` 中:
   ```java
   } catch (Exception e) {
       LOG.error("Failed to clear data for graph '{}': {}", options.graph, 
e.getMessage(), e);
       throw e;
   }
   ```
   
   而在其他地方使用 LOG.warn()。建议统一关键操作失败的日志级别。
   
   同时,既然已经在抛出异常前记录了 error 日志,上层再次捕获时可以考虑不重复记录,避免日志冗余。



-- 
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]

Reply via email to