Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exceptions handling and logs #168

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
11 changes: 6 additions & 5 deletions cse-cc-export-runner-app/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,24 @@
<durable>true</durable>
<deliveryMode>PERSISTENT</deliveryMode>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- This logger name must match Logger's names in java code
Do not bind any logger with the appender "amqp-business-events"!
You should bind with "amqp-business-events" appender only Loggers you want to see in gridcapa processes as a final user-->
<logger name="CSE_EXPORT_BUSINESS_LOGGER" additivity="false" level="INFO">
<appender-ref ref="amqp-business-events"/>
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.farao_community.farao.dichotomy.api.logging.TechnicalLogs" level="OFF">
<appender-ref ref="amqp-business-events"/>
</logger>


<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public DichotomyStepResult<DichotomyRaoResponse> 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());
String errorMessage = "Exception occurred during validation. Nested exception: {}" + e.getMessage();
LOGGER.error(errorMessage);
throw new ValidationException("RAO run failed", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 8 additions & 5 deletions cse-cc-import-runner-app/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,32 @@
<durable>true</durable>
<deliveryMode>PERSISTENT</deliveryMode>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- This logger name must match Logger's names in java code
Do not bind any logger with the appender "amqp-business-events"!
You should bind with "amqp-business-events" appender only Loggers you want to see in gridcapa processes as a final user-->
<logger name="CSE_BUSINESS_LOGGER" additivity="false" level="INFO">
<appender-ref ref="amqp-business-events"/>
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.farao_community.farao.dichotomy.api.logging.DichotomyBusinessLogs" level="INFO">
<appender-ref ref="amqp-business-events"/>
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.farao_community.farao.dichotomy.api.logging.DichotomyBusinessWarns" level="WARN">
<appender-ref ref="amqp-business-events"/>
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.farao_community.farao.dichotomy.api.logging.TechnicalLogs" level="OFF">
<appender-ref ref="amqp-business-events"/>
</logger>


<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<!-- BUSINESS DEPENDENCIES -->
<farao.dependencies.version>1.21.1</farao.dependencies.version>
<farao.dichotomy.version>4.13.3</farao.dichotomy.version>
<farao.dichotomy.version>4.13.4</farao.dichotomy.version>
<gridcapa.rao.runner.version>1.17.2</gridcapa.rao.runner.version>
<gridcapa.task-manager.version>1.21.0</gridcapa.task-manager.version>
<gridcapa.starter.minio.adapter.version>1.1.0</gridcapa.starter.minio.adapter.version>
Expand Down