From d6f255b7b26fac238783343e2f951e0f6530ccd8 Mon Sep 17 00:00:00 2001 From: Eloi Charpentier Date: Tue, 2 Jul 2024 14:29:41 +0200 Subject: [PATCH] core: add error when stdcm requests don't end with a stop --- .../java/fr/sncf/osrd/reporting/exceptions/ErrorType.java | 3 ++- .../kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt | 6 ++++-- front/public/locales/en/errors.json | 3 ++- front/public/locales/fr/errors.json | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java b/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java index a2c467285cd..1b0b91850eb 100644 --- a/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java +++ b/core/osrd-reporting/src/main/java/fr/sncf/osrd/reporting/exceptions/ErrorType.java @@ -152,7 +152,8 @@ public enum ErrorType { InconsistentSpeedSection( "speed_section", "Speed section definition is nonsensical and cannot be used for simulation", - ErrorCause.USER); + ErrorCause.USER), + MissingLastSTDCMStop("missing_last_stdcm_stop", "Last step of stdcm request needs to be a stop", ErrorCause.USER); public final String type; public final String message; diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt index 332519886bb..d93813cde2d 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt @@ -16,6 +16,7 @@ import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath import fr.sncf.osrd.envelope_sim_infra.MRSP import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.graph.PathfindingEdgeLocationId +import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl import fr.sncf.osrd.sim_infra.api.Block @@ -35,7 +36,6 @@ import fr.sncf.osrd.utils.units.Offset import fr.sncf.osrd.utils.units.meters import fr.sncf.osrd.utils.units.seconds import java.time.Duration.ofMillis -import java.util.HashSet import org.takes.Request import org.takes.Response import org.takes.Take @@ -174,7 +174,9 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take { } private fun parseSteps(infra: FullInfra, pathItems: List): List { - assert(pathItems.last().stopDuration != null) + if (pathItems.last().stopDuration == null) { + throw OSRDError(ErrorType.MissingLastSTDCMStop) + } return pathItems .map { STDCMStep( diff --git a/front/public/locales/en/errors.json b/front/public/locales/en/errors.json index 2ebab0419a5..50451a130b6 100644 --- a/front/public/locales/en/errors.json +++ b/front/public/locales/en/errors.json @@ -9,7 +9,8 @@ "default": "An error has occurred.", "pageNotFound": "The page you are looking for does not exist.", "core": { - "assert_error": "Assert error at {{file_location}}: {{assert_message}}" + "assert_error": "Assert error at {{file_location}}: {{assert_message}}", + "missing_last_stdcm_stop": "STDCM requests that don't end with a stop aren't currently supported" }, "editoast": { "attached": { diff --git a/front/public/locales/fr/errors.json b/front/public/locales/fr/errors.json index 3280fd4425d..58273664649 100644 --- a/front/public/locales/fr/errors.json +++ b/front/public/locales/fr/errors.json @@ -9,7 +9,8 @@ "default": "Une erreur est survenue.", "pageNotFound": "La page que vous recherchez n'existe pas.", "core": { - "assert_error": "Assertion échouée à {{file_location}}: {{assert_message}}" + "assert_error": "Assertion échouée à {{file_location}}: {{assert_message}}", + "missing_last_stdcm_stop": "Les requêtes STDCM ne finissant pas par un arrêt ne sont pas actuellement supportées" }, "editoast": { "attached": {