From fa605c7fc773071adef5f0c8fbdfee713809449a Mon Sep 17 00:00:00 2001 From: Vincent BOCHET Date: Wed, 8 Nov 2023 17:17:59 +0100 Subject: [PATCH 1/2] Improve exceptions handling and logs --- .../farao/cse/export_runner/app/FileUtil.java | 2 +- .../export_runner/app/services/FileExporter.java | 2 +- .../export_runner/app/services/FileImporter.java | 4 ++-- .../app/services/RaoRunnerService.java | 2 +- .../src/main/resources/logback.xml | 11 ++++++----- .../app/dichotomy/RaoRunnerValidator.java | 4 ++-- .../import_runner/app/services/FileExporter.java | 2 +- .../import_runner/app/services/FileImporter.java | 6 +++--- .../farao/cse/import_runner/app/util/FileUtil.java | 2 +- .../src/main/resources/logback.xml | 13 ++++++++----- .../busbar_change/NetworkModifier.java | 8 ++++---- pom.xml | 2 +- 12 files changed, 31 insertions(+), 27 deletions(-) diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/FileUtil.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/FileUtil.java index 9218de45..ab697703 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/FileUtil.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/FileUtil.java @@ -30,7 +30,7 @@ public static String getFilenameFromUrl(String stringUrl) { URL url = new URL(stringUrl); return FilenameUtils.getName(url.getPath()); } catch (IOException e) { - throw new CseDataException(String.format("Exception occurred while retrieving file name from : %s Cause: %s ", stringUrl, e.getMessage())); + throw new CseDataException(String.format("Exception occurred while retrieving file name from : %s", stringUrl), e); } } diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileExporter.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileExporter.java index a9b2b809..4323c3a7 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileExporter.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileExporter.java @@ -130,7 +130,7 @@ String saveTtcRao(CseRaoResult cseRaoResult, ProcessType processType, OffsetDate jaxbMarshaller.marshal(root, stringWriter); } catch (JAXBException e) { - throw new CseInternalException("XSD matching error"); + throw new CseInternalException("XSD matching error", e); } ByteArrayInputStream is = new ByteArrayInputStream(stringWriter.toString().getBytes()); String ttcPath = getDestinationPath(processTargetDate, processType, GridcapaFileGroup.OUTPUT) + getTtcRaoResultOutputFilename(processTargetDate, initialCgmFilename, processType); diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java index 20bf12e5..e5a68228 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/FileImporter.java @@ -58,8 +58,8 @@ private InputStream openUrlStream(String urlString) { URL url = new URL(urlString); return url.openStream(); // NOSONAR Usage of whitelist not triggered by Sonar quality assessment, even if listed as a solution to the vulnerability } catch (IOException e) { - businessLogger.error("Error while retrieving content of file : {}, Link may have expired.", FileUtil.getFilenameFromUrl(urlString)); - throw new CseDataException(String.format("Exception occurred while retrieving file content from : %s Cause: %s ", urlString, e.getMessage())); + businessLogger.error("Error while retrieving content of file \"{}\", link may have expired.", FileUtil.getFilenameFromUrl(urlString)); + throw new CseDataException(String.format("Exception occurred while retrieving file content from %s", urlString), e); } } diff --git a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java index 1f11b71b..97ed8441 100644 --- a/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java +++ b/cse-cc-export-runner-app/src/main/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerService.java @@ -36,7 +36,7 @@ public RaoResponse run(String id, String networkPresignedUrl, String cracInJsonF LOGGER.info("RAO response received: {}", raoResponse); return raoResponse; } catch (Exception e) { - throw new CseInternalException("RAO run failed. Nested exception: " + e.getMessage()); + throw new CseInternalException("RAO run failed", e); } } diff --git a/cse-cc-export-runner-app/src/main/resources/logback.xml b/cse-cc-export-runner-app/src/main/resources/logback.xml index 4339a833..e1dac5ae 100644 --- a/cse-cc-export-runner-app/src/main/resources/logback.xml +++ b/cse-cc-export-runner-app/src/main/resources/logback.xml @@ -38,23 +38,24 @@ true PERSISTENT + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + - - - %d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java index 26cfd11c..10997a14 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java @@ -104,8 +104,8 @@ public DichotomyStepResult validateNetwork(Network network DichotomyRaoResponse dichotomyRaoResponse = new DichotomyRaoResponse(raoResponse, appliedForcedPras); return DichotomyStepResult.fromNetworkValidationResult(raoResult, dichotomyRaoResponse); } catch (RuntimeException e) { - LOGGER.error("Exception occured during validation", e); - throw new ValidationException("RAO run failed. Nested exception: " + e.getMessage()); + LOGGER.error("Exception occured during validation. Nested exception: " + e.getMessage()); + throw new ValidationException("RAO run failed", e); } } diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileExporter.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileExporter.java index 44b783c5..f8813b57 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileExporter.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileExporter.java @@ -133,7 +133,7 @@ String saveTtcResult(Timestamp timestamp, OffsetDateTime processTargetDate, Proc jaxbMarshaller.marshal(root, stringWriter); } catch (JAXBException e) { - throw new CseInternalException("XSD matching error"); + throw new CseInternalException("XSD matching error", e); } InputStream is = new ByteArrayInputStream(stringWriter.toString().getBytes()); String outputFilePath = getFilePath(processTargetDate, processType, isImportEc); diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java index e9c6ddb6..b54e1eef 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/services/FileImporter.java @@ -166,8 +166,8 @@ InputStream openUrlStream(String urlString) { URL url = new URL(urlString); return url.openStream(); // NOSONAR Usage of whitelist not triggered by Sonar quality assessment, even if listed as a solution to the vulnerability } catch (IOException e) { - businessLogger.error("Error while retrieving content of file : {}, Link may have expired.", getFileNameFromUrl(urlString)); - throw new CseDataException(String.format("Exception occurred while retrieving file content from : %s Cause: %s ", urlString, e.getMessage())); + businessLogger.error("Error while retrieving content of file \"{}\", link may have expired.", getFileNameFromUrl(urlString)); + throw new CseDataException(String.format("Exception occurred while retrieving file content from %s", urlString), e); } } @@ -176,7 +176,7 @@ private String getFileNameFromUrl(String stringUrl) { URL url = new URL(stringUrl); return FilenameUtils.getName(url.getPath()); } catch (IOException e) { - throw new CseDataException(String.format("Exception occurred while retrieving file name from : %s Cause: %s ", stringUrl, e.getMessage())); + throw new CseDataException(String.format("Exception occurred while retrieving file name from : %s", stringUrl), e); } } diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/FileUtil.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/FileUtil.java index fa2904a5..d6dfb623 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/FileUtil.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/util/FileUtil.java @@ -26,7 +26,7 @@ public static String getFilenameFromUrl(String url) { try { return FilenameUtils.getName(new URL(url).getPath()); } catch (MalformedURLException e) { - throw new CseInvalidDataException(String.format("URL is invalid: %s", url)); + throw new CseInvalidDataException(String.format("URL is invalid: %s", url), e); } } } diff --git a/cse-cc-import-runner-app/src/main/resources/logback.xml b/cse-cc-import-runner-app/src/main/resources/logback.xml index 238a47d0..b7543615 100644 --- a/cse-cc-import-runner-app/src/main/resources/logback.xml +++ b/cse-cc-import-runner-app/src/main/resources/logback.xml @@ -38,29 +38,32 @@ true PERSISTENT + + + %d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + - - - %d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - diff --git a/cse-lib/network-processing/src/main/java/com/farao_community/farao/cse/network_processing/busbar_change/NetworkModifier.java b/cse-lib/network-processing/src/main/java/com/farao_community/farao/cse/network_processing/busbar_change/NetworkModifier.java index b581a012..a3fc821c 100644 --- a/cse-lib/network-processing/src/main/java/com/farao_community/farao/cse/network_processing/busbar_change/NetworkModifier.java +++ b/cse-lib/network-processing/src/main/java/com/farao_community/farao/cse/network_processing/busbar_change/NetworkModifier.java @@ -56,7 +56,7 @@ public Bus createBus(String newBusId, String voltageLevelId) { LOGGER.debug("New bus '{}' has been created", newBus.getId()); return newBus; } catch (PowsyblException e) { - throw new FaraoException(String.format("Could not create bus %s: %s", newBusId, e.getMessage())); + throw new FaraoException(String.format("Could not create bus %s", newBusId), e); } } @@ -106,7 +106,7 @@ public Switch createSwitch(VoltageLevel voltageLevel, String bus1Id, String bus2 LOGGER.debug("New switch '{}' has been created", newSwitch.getId()); return newSwitch; } catch (PowsyblException e) { - throw new FaraoException(String.format("Could not create switch between %s and %s: %s", bus1Id, bus2Id, e.getMessage())); + throw new FaraoException(String.format("Could not create switch between %s and %s", bus1Id, bus2Id), e); } } @@ -143,7 +143,7 @@ public void moveBranch(Branch branch, Branch.Side side, Bus bus) { throw new FaraoException(String.format("Cannot move %s of type %s", branch.getId(), branch.getClass())); } } catch (PowsyblException e) { - throw new FaraoException(String.format("Could not move line %s: %s", branch.getId(), e.getMessage())); + throw new FaraoException(String.format("Could not move line %s", branch.getId()), e); } } @@ -409,7 +409,7 @@ public void commitAllChanges() { busesToRemove = new HashSet<>(); cleanAliases(); } catch (PowsyblException e) { - throw new FaraoException(String.format("Could not apply all changes to network: %s", e.getMessage())); + throw new FaraoException("Could not apply all changes to network", e); } } diff --git a/pom.xml b/pom.xml index 3688a553..4c4f6545 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ 1.21.1 - 4.13.3 + 4.13.4 1.17.2 1.21.0 1.1.0 From f76b20f8b6603890d9fdfb5a1591df867173e2b0 Mon Sep 17 00:00:00 2001 From: Vincent BOCHET Date: Fri, 10 Nov 2023 15:05:04 +0100 Subject: [PATCH 2/2] Code review --- .../cse/import_runner/app/dichotomy/RaoRunnerValidator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java index 10997a14..a0632150 100644 --- a/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java +++ b/cse-cc-import-runner-app/src/main/java/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidator.java @@ -104,7 +104,8 @@ public DichotomyStepResult validateNetwork(Network network DichotomyRaoResponse dichotomyRaoResponse = new DichotomyRaoResponse(raoResponse, appliedForcedPras); return DichotomyStepResult.fromNetworkValidationResult(raoResult, dichotomyRaoResponse); } catch (RuntimeException e) { - LOGGER.error("Exception occured during validation. Nested exception: " + e.getMessage()); + String errorMessage = "Exception occurred during validation. Nested exception: {}" + e.getMessage(); + LOGGER.error(errorMessage); throw new ValidationException("RAO run failed", e); } }