Skip to content

Commit

Permalink
fix(weaver): improper exception handling
Browse files Browse the repository at this point in the history
This pull request addresses the issue of improper exception handling. The need is to wrap the expected exceptions in a try-catch block and handle them explicitly.

Changes:

Enclosed the existing code within a try-catch block to capture exceptions.
Added contextual information in the logs, and the exception is re-thrown within the getConfig() function, as part of the exception propagation process.

fixes #2767

Signed-off-by: D.Yogesh <[email protected]>
  • Loading branch information
Yogesh01000100 committed Oct 25, 2023
1 parent dcaf9fe commit 68c12a8
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 68c12a8

Please sign in to comment.