diff --git a/backend/api/EventHandlers/MissionEventHandler.cs b/backend/api/EventHandlers/MissionEventHandler.cs index 374c3765a..7929fcc62 100644 --- a/backend/api/EventHandlers/MissionEventHandler.cs +++ b/backend/api/EventHandlers/MissionEventHandler.cs @@ -149,6 +149,7 @@ private async void OnLocalizationMissionSuccessful(object? sender, LocalizationM _startMissionSemaphore.WaitOne(); try { await MissionScheduling.StartNextMissionRunIfSystemIsAvailable(robot.Id); } catch (MissionRunNotFoundException) { return; } + catch (DatabaseUpdateException) { return; } finally { _startMissionSemaphore.Release(); } } diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index ea37de6c0..4066b192a 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -382,7 +382,10 @@ private async void OnIsarTaskUpdate(object? sender, MqttReceivedArgs mqttArgs) catch (MissionTaskNotFoundException) { return; } var missionRun = await MissionRunService.ReadByIsarMissionId(task.MissionId); - if (missionRun is null) _logger.LogWarning("Mission run with ID {Id} was not found", task.MissionId); + if (missionRun is null) + { + _logger.LogWarning("Mission run with ID {Id} was not found", task.MissionId); + } _ = SignalRService.SendMessageAsync("Mission run updated", missionRun?.Area?.Installation, missionRun != null ? new MissionRunResponse(missionRun) : null); diff --git a/backend/api/Services/MissionRunService.cs b/backend/api/Services/MissionRunService.cs index 41ac44e79..300f94e83 100644 --- a/backend/api/Services/MissionRunService.cs +++ b/backend/api/Services/MissionRunService.cs @@ -78,7 +78,15 @@ public async Task Create(MissionRun missionRun, bool triggerCreatedM { missionRun.Id ??= Guid.NewGuid().ToString(); // Useful for signalR messages // Making sure database does not try to create new robot - context.Entry(missionRun.Robot).State = EntityState.Unchanged; + try + { + context.Entry(missionRun.Robot).State = EntityState.Unchanged; + } + catch (InvalidOperationException e) + { + throw new DatabaseUpdateException($"Unable to create mission. {e}"); + } + if (IncludesUnsupportedInspectionType(missionRun)) { diff --git a/backend/api/Utilities/Exceptions.cs b/backend/api/Utilities/Exceptions.cs index 957ef4ca7..fb44d1d3f 100644 --- a/backend/api/Utilities/Exceptions.cs +++ b/backend/api/Utilities/Exceptions.cs @@ -120,4 +120,8 @@ public class RobotCurrentAreaMissingException(string message) : Exception(messag public class UnsupportedRobotCapabilityException(string message) : Exception(message) { } + + public class DatabaseUpdateException(string message) : Exception(message) + { + } }