From 7058abd6e46ffc9e5cac99639addff018353061b Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Fri, 15 Nov 2024 22:52:25 -0300 Subject: [PATCH] applies format and improve fault tolerancy for creation logs on controllers --- lib/controllers/environment.py | 7 ++++++- lib/controllers/flight.py | 6 +++++- lib/controllers/motor.py | 7 ++++++- lib/controllers/rocket.py | 7 ++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/controllers/environment.py b/lib/controllers/environment.py index bb2b09b..40bd7bd 100644 --- a/lib/controllers/environment.py +++ b/lib/controllers/environment.py @@ -56,9 +56,14 @@ async def create_env(env: Env) -> Union[EnvCreated, HTTPException]: else: return EnvCreated(env_id=env_repo.env_id) finally: + env_id = ( + getattr(env_repo, 'env_id', 'unknown') + if env_repo + else 'unknown' + ) if env_repo: logger.info( - f"Call to controllers.environment.create_env completed for Env {env_repo.env_id}" + f"Call to controllers.environment.create_env completed for Env {env_id}" ) @staticmethod diff --git a/lib/controllers/flight.py b/lib/controllers/flight.py index 7aa7ad0..1d2aa8d 100644 --- a/lib/controllers/flight.py +++ b/lib/controllers/flight.py @@ -73,7 +73,11 @@ async def create_flight( else: return FlightCreated(flight_id=flight_repo.flight_id) finally: - flight_id = getattr(flight_repo, 'flight_id', 'unknown') if flight_repo else 'unknown' + flight_id = ( + getattr(flight_repo, 'flight_id', 'unknown') + if flight_repo + else 'unknown' + ) logger.info( f"Call to controllers.flight.create_flight completed for Flight {flight_id}" ) diff --git a/lib/controllers/motor.py b/lib/controllers/motor.py index 10fad67..824dfd1 100644 --- a/lib/controllers/motor.py +++ b/lib/controllers/motor.py @@ -69,9 +69,14 @@ async def create_motor( else: return MotorCreated(motor_id=motor_repo.motor_id) finally: + motor_id = ( + getattr(motor_repo, 'motor_id', 'unknown') + if motor_repo + else 'unknown' + ) if motor_repo: logger.info( - f"Call to controllers.motor.create_motor completed for Motor {motor_repo.motor_id}" + f"Call to controllers.motor.create_motor completed for Motor {motor_id}" ) @staticmethod diff --git a/lib/controllers/rocket.py b/lib/controllers/rocket.py index 4a7ad17..5b42b60 100644 --- a/lib/controllers/rocket.py +++ b/lib/controllers/rocket.py @@ -63,9 +63,14 @@ async def create_rocket( else: return RocketCreated(rocket_id=rocket_repo.rocket_id) finally: + rocket_id = ( + getattr(rocket_repo, 'rocket_id', 'unknown') + if rocket_repo + else 'unknown' + ) if rocket_repo: logger.info( - f"Call to controllers.rocket.create_rocket completed for Rocket {rocket_repo.rocket_id}" + f"Call to controllers.rocket.create_rocket completed for Rocket {rocket_id}" ) @staticmethod