Skip to content

Commit

Permalink
core: remove unused isCacheable and introduce unrecoverable for errors
Browse files Browse the repository at this point in the history
So far any recoverable error is "cacheable/serializable" for simulation
or pathfinding.

Signed-off-by: Pierre-Etienne Bougué <[email protected]>
  • Loading branch information
bougue-pe committed Nov 7, 2024
1 parent cb4e0bc commit a243a35
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum ErrorType {
StrictWarningError("strict_warning", "Warning was reported with strict mode enabled", ErrorCause.USER),
AssertionError("assert_error", "assert check failed", ErrorCause.INTERNAL),
UnknownError("unknown_error", "An unknown exception was thrown", ErrorCause.INTERNAL),
InfraSoftLoadingError("infra_loading:soft_error", "soft error while loading new infra", ErrorCause.USER, false),
InfraSoftLoadingError("infra_loading:soft_error", "soft error while loading new infra", ErrorCause.USER, true),
InfraHardLoadingError("infra_loading:hard_error", "hard error while loading new infra", ErrorCause.USER),
InfraHardError("infra:hard_error", "hard error while parsing infra", ErrorCause.USER),
InfraLoadingCacheException("infra_loading:cache_exception", "cached exception", ErrorCause.INTERNAL),
Expand Down Expand Up @@ -175,16 +175,16 @@ public enum ErrorType {
public final String type;
public final String message;
public final ErrorCause cause;
public final boolean isCacheable;
public final boolean unrecoverable;

ErrorType(String type, String message, ErrorCause cause) {
this(type, message, cause, true);
this(type, message, cause, false);
}

ErrorType(String type, String message, ErrorCause cause, boolean isCacheable) {
ErrorType(String type, String message, ErrorCause cause, boolean unrecoverable) {
this.type = "core:" + type;
this.message = message;
this.cause = cause;
this.isCacheable = isCacheable;
this.unrecoverable = unrecoverable;
}
}
3 changes: 1 addition & 2 deletions core/src/main/java/fr/sncf/osrd/api/ExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fr.sncf.osrd.api;

import fr.sncf.osrd.reporting.exceptions.ErrorCause;
import fr.sncf.osrd.reporting.exceptions.ErrorType;
import fr.sncf.osrd.reporting.exceptions.OSRDError;
import org.takes.Response;
import org.takes.rs.RsJson;
Expand All @@ -15,7 +14,7 @@ public class ExceptionHandler {
public static Response handle(Throwable ex) throws OSRDError {
ex.printStackTrace();
if (ex instanceof OSRDError osrdError) {
if (osrdError.osrdErrorType == ErrorType.InfraSoftLoadingError) {
if (osrdError.osrdErrorType.unrecoverable) {
throw osrdError;
}
return toResponse(osrdError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PathfindingBlocksEndpointV2(private val infraManager: InfraManager) : Take
pathfindingLogger.info("No path found")
RsJson(RsWithBody(pathfindingResponseAdapter.toJson(error.response)))
} catch (ex: Throwable) {
if (ex is OSRDError && ex.osrdErrorType.isCacheable) {
if (ex is OSRDError && !ex.osrdErrorType.unrecoverable) {
pathfindingLogger.info("Pathfinding failed: ${ex.message}")
val response = PathfindingFailed(ex)
RsJson(RsWithBody(pathfindingResponseAdapter.toJson(response)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SimulationEndpoint(
)
return RsJson(RsWithBody(simulationResponseAdapter.toJson(res)))
} catch (ex: Throwable) {
if (ex is OSRDError && ex.osrdErrorType.isCacheable) {
if (ex is OSRDError && !ex.osrdErrorType.unrecoverable) {
val response = SimulationFailed(ex)
return RsJson(RsWithBody(simulationResponseAdapter.toJson(response)))
}
Expand Down

0 comments on commit a243a35

Please sign in to comment.