Error handling

This page describes how to handle the returned errors from the ScenarioPlayer.

Error definition

Interacting with the scenario player can lead to some errors. You'll find below the different exceptions that can be returned depending of the kind of error.

enum ScenarioPlayerException: Error {
  case CannotLoadScenarioException(ErrorResponse)
  case ScenarioNotFoundException(Int, [Int])
  case NoScenariosReceivedException
  case NoScenarioLoadedException
  case NoScenarioInstanceIdDefinedException(Int)
  case PlayerAlreadyStartedException
  case NoScenarioConfigFoundException(Int, Int)
  case NoScenarioStepsFoundException(Int, Int)
  case NoScenarioStepLayoutFoundException(Int, Int)
  case ScenarioConfigInvalidException(Int, Int)
  case InvalidObserverTypeException
}
  • CannotLoadScenarioException: is returned when the scenario player couldn't load the scenario(s) from the Inarix API. It holds the received error response to help debugging the error. You can access the error message using the message member and the error code using the errorCode member.
  • ScenarioNotFoundException: is returned when the scenario player couldn't find the requested scenario in the list of authorized scenarios sent by the Inarix API.
  • NoScenariosReceivedException: is returned when the scenario player didn't receive any scenarios from the Inarix API.
  • NoScenarioLoadedException: is returned when starting the scenario player without a scenario loaded.
  • NoScenarioInstanceIdDefinedException: is returned when the scenario received from the Inarix API is missing the definition of the scenario. Therefore, the scenario player isn't able to run the requested scenario.
  • PlayerAlreadyStartedException: is returned when you already started a session on the scenario player without terminating it. You need to first terminate the session on the scenario player and then start a new session.
  • NoScenarioConfigFoundException: is returned when the scenario player couldn't find the scenario's configuration within its definition.
  • NoScenarioStepsFoundException: is returned when the scenario player couldn't find the scenario's steps' definitions within the scenario's definition.
  • NoScenarioStepLayoutFoundException: is returned when the requested scenario doesn't have a layout within its configuration.
  • ScenarioConfigInvalidException: is returned when the scenario player found a mistake within the scenario's layout configuration.
  • InvalidObserverTypeException: is thrown when trying to observe an EventType with the wrong observer.

Listening to errors

Now that you're familiar with the concept of observers, it is exactly the same principle but using a different publisher. You'll find an example below to listen on error when using the scenario player:

@Observable
class ViewModel: InarixSDK.ScenarioPlayer.ErrorObserver {
	func onError(error: any Error) {
    // Handle error here
    debugPrint(error)
  }
}

First, you have to follow from the protocol InarixSDK.ScenarioPlayer.ErrorObserver and define a function called onError which takes any type of Error in parameter. This function is used to notify you when the scenario player encountered an error.

func setupPlayer() {
  self.player = InarixSDK.ScenarioPlayer()

  // Register an observer instance to catch errors
  try? self.player.listenOn(eventType: .error, observer: self)
  
  /*
  * ...
  */
}

Finally, in your setup function (or anywhere you want), you can register your observer to the Inarix SDK ScenarioPlayer.ErrorPublisher.


What’s Next

We are able to listen on errors and react to it accordingly. Moreover, some scenarios may require to set annotations through code instead of doing it manually 🔬.