Skip to content

Commit

Permalink
fix(weaver): improper exception handling
Browse files Browse the repository at this point in the history
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 <yogeshone678@gmail.com>
  • Loading branch information
Yogesh01000100 authored and petermetz committed Jan 24, 2024
1 parent 1668cf4 commit a33f30c
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 a33f30c

Please sign in to comment.