Skip to content

Commit

Permalink
Improve error messages in scheduling_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
GodVenn committed Jun 9, 2022
1 parent 21d8bb1 commit 00a89a9
Showing 1 changed file with 49 additions and 39 deletions.
88 changes: 49 additions & 39 deletions src/isar/apis/schedule/scheduling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ def start_mission(
try:
state: States = self.scheduling_utilities.get_state()
except Empty:
self.logger.error(
errorMsg: str = (
"Internal Server Error - Current state of state machine unknown"
)
self.logger.error(errorMsg)
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
return
return errorMsg

if state in [
States.Initialize,
Expand All @@ -73,16 +74,17 @@ def start_mission(
States.Monitor,
States.Paused,
]:
self.logger.warning("Conflict - Mission already in progress")
errorMsg = "Conflict - Mission already in progress"
self.logger.warning(errorMsg)
response.status_code = HTTPStatus.CONFLICT.value
return
return errorMsg

try:
mission: Mission = self.mission_planner.get_mission(mission_id)
except HTTPError as e:
self.logger.error(e)
response.status_code = e.response.status_code
return
raise
except MissionPlannerError as e:
self.logger.error(e)
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
Expand All @@ -92,11 +94,10 @@ def start_mission(
mission=mission, robot_capabilities=robot_settings.CAPABILITIES
)
if not robot_capable:
self.logger.error(
"Bad Request - Robot is not capable of performing mission"
)
errorMsg = "Bad Request - Robot is not capable of performing mission"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.BAD_REQUEST.value
return
return errorMsg

initial_pose_alitra: Optional[Pose]
if initial_pose:
Expand Down Expand Up @@ -142,9 +143,10 @@ def start_mission(
)
self.logger.info("OK - Mission successfully started")
except QueueTimeoutError:
errorMsg = "Timeout - Failed to start mission"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.REQUEST_TIMEOUT.value
self.logger.error("Timeout - Failed to start mission")
return
return errorMsg
return StartMissionResponse(**mission.api_response_dict())

def pause_mission(self, response: Response):
Expand All @@ -153,34 +155,35 @@ def pause_mission(self, response: Response):
try:
state: States = self.scheduling_utilities.get_state()
except Empty:
self.logger.error(
"Internal Server Error - Current state of state machine unknown"
)
errorMsg = "Internal Server Error - Current state of state machine unknown"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
return
return errorMsg

if state in [States.Idle, States.StopStep, States.Paused, States.Initialize]:
self.logger.info("Conflict - Pause command received in invalid state")
errorMsg = "Conflict - Pause command received in invalid state"
self.logger.warning(errorMsg)
response.status_code = HTTPStatus.CONFLICT.value
return
return errorMsg

try:
self.scheduling_utilities.pause_mission()
self.logger.info("OK - Mission successfully paused")
except QueueTimeoutError:
self.logger.error("Timeout - Failed to pause mission")
errorMsg = "Timeout - Failed to pause mission"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.REQUEST_TIMEOUT.value
return errorMsg

def resume_mission(self, response: Response):
self.logger.info("Received request to resume current mission")
try:
state: States = self.scheduling_utilities.get_state()
except Empty:
self.logger.error(
"Internal Server Error - Current state of state machine unknown"
)
errorMsg = "Internal Server Error - Current state of state machine unknown"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
return
return errorMsg

if state in [
States.Idle,
Expand All @@ -189,40 +192,45 @@ def resume_mission(self, response: Response):
States.StopStep,
States.Initialize,
]:
self.logger.info("Conflict - Resume command received in invalid state")
errorMsg = "Conflict - Resume command received in invalid state"
self.logger.warning(errorMsg)
response.status_code = HTTPStatus.CONFLICT.value
return
return errorMsg

try:
self.scheduling_utilities.resume_mission()
self.logger.info("OK - Mission successfully resumed")
except QueueTimeoutError:
self.logger.error("Timeout - Failed to resume mission")
errorMsg = "Timeout - Failed to resume mission"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.REQUEST_TIMEOUT.value
return errorMsg

def stop_mission(self, response: Response):
self.logger.info("Received request to stop current mission")

try:
state: States = self.scheduling_utilities.get_state()
except Empty:
self.logger.error(
"Internal Server Error - Current state of state machine unknown"
)
errorMsg = "Internal Server Error - Current state of state machine unknown"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
return
return errorMsg

if state in [States.Idle, States.Initialize]:
self.logger.info("Conflict - Stop command received in invalid state")
errorMsg = "Conflict - Stop command received in invalid state"
self.logger.warning(errorMsg)
response.status_code = HTTPStatus.CONFLICT.value
return
return errorMsg

try:
self.scheduling_utilities.stop_mission()
self.logger.info("OK - Mission successfully stopped")
except QueueTimeoutError:
self.logger.error("Timeout - Failed to stop mission")
errorMsg = "Timeout - Failed to stop mission"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.REQUEST_TIMEOUT.value
return errorMsg

def drive_to(
self,
Expand Down Expand Up @@ -251,11 +259,10 @@ def drive_to(
try:
state: States = self.scheduling_utilities.get_state()
except Empty:
self.logger.error(
"Internal Server Error - Current state of state machine unknown"
)
errorMsg = "Internal Server Error - Current state of state machine unknown"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR.value
return
return errorMsg

if state in [
States.Initialize,
Expand All @@ -264,9 +271,10 @@ def drive_to(
States.Monitor,
States.Paused,
]:
self.logger.info("Conflict - Drivt to command received in invalid state")
errorMsg = "Conflict - DriveTo command received in invalid state"
self.logger.warning(errorMsg)
response.status_code = HTTPStatus.CONFLICT.value
return
return errorMsg

robot_frame: Frame = Frame("robot")
position: Position = Position(x=x, y=y, z=z, frame=robot_frame)
Expand All @@ -282,5 +290,7 @@ def drive_to(
self.scheduling_utilities.start_mission(mission=mission, initial_pose=None)
self.logger.info("OK - Drive to successfully started")
except QueueTimeoutError:
self.logger.error("Timout - Failed to start drive to")
errorMsg = "Timeout - Failed to start DriveTo"
self.logger.error(errorMsg)
response.status_code = HTTPStatus.REQUEST_TIMEOUT.value
return errorMsg

0 comments on commit 00a89a9

Please sign in to comment.