Skip to content

Commit a33f30c

Browse files
Yogesh01000100petermetz
authored andcommitted
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 <[email protected]>
1 parent 1668cf4 commit a33f30c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

weaver/sdks/corda/src/main/kotlin/org/hyperledger/cacti/weaver/sdk/corda/CredentialsExtractor.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,19 @@ private static JsonObject getNodeTlsCertChain(KeyStore ks, JsonObject configObj,
290290
return configObj;
291291
}
292292

293-
private static void deleteFolder(File folder) {
293+
private static void deleteFolder(File folder) throws Exception {
294294
if (folder.isDirectory()) {
295-
for (File subf: folder.listFiles()) {
296-
deleteFolder(subf);
295+
for (File subf : folder.listFiles()) {
296+
try {
297+
deleteFolder(subf);
298+
} catch (Exception e) {
299+
String errorMessage = "An error occurred while deleting : " + subf.getPath();
300+
throw new Exception(errorMessage);
301+
}
297302
}
298303
}
299304
folder.delete();
305+
System.out.println((folder.exists() ? "Failed to delete : " : "Deleted successfully : ") + folder.getPath());
300306
}
301307

302308
public static String getConfig(String baseNodesPath, String[] nodes) {
@@ -326,7 +332,11 @@ public static String getConfig(String baseNodesPath, String[] nodes) {
326332
//}
327333
configObj.add(node, nodeConfigObj);
328334
}
329-
deleteFolder(new File(tempStore));
335+
try {
336+
deleteFolder(new File(tempStore));
337+
} catch (Exception e) {
338+
e.printStackTrace();
339+
}
330340
System.out.println("Extracted configuration for " + node);
331341
}
332342
System.out.println("Extracted configuration for all nodes");

0 commit comments

Comments
 (0)