From a33f30c07cb7b952581c2401da60a25170b23d1c Mon Sep 17 00:00:00 2001 From: "D.Yogesh" Date: Tue, 17 Oct 2023 12:52:54 -0700 Subject: [PATCH] fix(weaver): improper exception handling Address improper exception handling by wrapping expected exceptions in a try-catch block and managing them explicitly. Changes: - Code is now enclosed within a try-catch to capture exceptions. - Logs include contextual information for clarity. - Exceptions re-thrown in getConfig() as part of propagation. fixes #2767 Signed-off-by: D.Yogesh --- .../weaver/sdk/corda/CredentialsExtractor.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/weaver/sdks/corda/src/main/kotlin/org/hyperledger/cacti/weaver/sdk/corda/CredentialsExtractor.java b/weaver/sdks/corda/src/main/kotlin/org/hyperledger/cacti/weaver/sdk/corda/CredentialsExtractor.java index 8b36177e22..cb02067823 100644 --- a/weaver/sdks/corda/src/main/kotlin/org/hyperledger/cacti/weaver/sdk/corda/CredentialsExtractor.java +++ b/weaver/sdks/corda/src/main/kotlin/org/hyperledger/cacti/weaver/sdk/corda/CredentialsExtractor.java @@ -290,13 +290,19 @@ private static JsonObject getNodeTlsCertChain(KeyStore ks, JsonObject configObj, return configObj; } - private static void deleteFolder(File folder) { + private static void deleteFolder(File folder) throws Exception { if (folder.isDirectory()) { - for (File subf: folder.listFiles()) { - deleteFolder(subf); + for (File subf : folder.listFiles()) { + try { + deleteFolder(subf); + } catch (Exception e) { + String errorMessage = "An error occurred while deleting : " + subf.getPath(); + throw new Exception(errorMessage); + } } } folder.delete(); + System.out.println((folder.exists() ? "Failed to delete : " : "Deleted successfully : ") + folder.getPath()); } public static String getConfig(String baseNodesPath, String[] nodes) { @@ -326,7 +332,11 @@ public static String getConfig(String baseNodesPath, String[] nodes) { //} configObj.add(node, nodeConfigObj); } - deleteFolder(new File(tempStore)); + try { + deleteFolder(new File(tempStore)); + } catch (Exception e) { + e.printStackTrace(); + } System.out.println("Extracted configuration for " + node); } System.out.println("Extracted configuration for all nodes");