From d60d5cb7169084f4623cde3ec76da3637fb7858d Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Thu, 2 Sep 2021 19:35:20 +0200 Subject: [PATCH] replace exceptions by error messages --- aman/formats/SctEseFormat.py | 28 ++++++++++++++++++---------- aman/types/Exception.py | 13 ------------- 2 files changed, 18 insertions(+), 23 deletions(-) delete mode 100644 aman/types/Exception.py diff --git a/aman/formats/SctEseFormat.py b/aman/formats/SctEseFormat.py index 3bebe77..824ac62 100644 --- a/aman/formats/SctEseFormat.py +++ b/aman/formats/SctEseFormat.py @@ -3,7 +3,6 @@ import sys from aman.types.ArrivalRoute import ArrivalRoute -from aman.types.Exception import FormatError, InputError from aman.types.Waypoint import Waypoint class SctEseFormat: @@ -29,7 +28,8 @@ class SctEseFormat: def parseWaypoint(waypoint : str, nameIdx : int, latitudeIdx : int, longitudeIdx : int): split = list(filter(None, waypoint.split(' '))) if len(split) <= longitudeIdx: - raise FormatError('Invalid waypoint format: ' + waypoint) + sys.stderr.write('Invalid waypoint format: ' + waypoint) + sys.exit(-1) return Waypoint(split[nameIdx], Waypoint.dms2dd(split[latitudeIdx]), Waypoint.dms2dd(split[longitudeIdx])) def extractWaypoints(self, sctFilepath : str): @@ -50,13 +50,17 @@ class SctEseFormat: foundAirports = True if False == foundVOR: - raise FormatError('Unable to find VOR-entries in the sector file') + sys.stderr.write('Unable to find VOR-entries in the sector file') + sys.exit(-1) if False == foundNDB: - raise FormatError('Unable to find NDB-entries in the sector file') + sys.stderr.write('Unable to find NDB-entries in the sector file') + sys.exit(-1) if False == foundFix: - raise FormatError('Unable to find FIX-entries in the sector file') + sys.stderr.write('Unable to find FIX-entries in the sector file') + sys.exit(-1) if False == foundAirports: - raise FormatError('Unable to find AIRPORT-entries in the sector file') + sys.stderr.write('Unable to find AIRPORT-entries in the sector file') + sys.exit(-1) # extract all waypoints for waypoint in config['VOR']: @@ -88,7 +92,8 @@ class SctEseFormat: coordinates = self.waypoints[waypoint] # no waypoint with this name defined if None == coordinates: - raise FormatError('Unable to find waypoint ' + waypoint) + sys.stderr.write('Unable to find waypoint ' + waypoint) + sys.exit(-1) # multiple waypoints, but use Haversine distance to distinct between candidates elif 1 != len(coordinates): minDistance = sys.float_info.max @@ -103,7 +108,8 @@ class SctEseFormat: nearest = coordinate if None == nearest: - raise InputError('Unable to find a close waypoint for ' + waypoint) + sys.stderr.write('Unable to find a close waypoint for ' + waypoint) + sys.exit(-1) waypoints.append(nearest) # extend the list of waypoints @@ -119,7 +125,8 @@ class SctEseFormat: # search the airport in the extracted list if not airport in self.airports: - raise InputError(airport + 'in self.airports', 'Unable to find the requested airport') + sys.stderr.write(airport + 'in self.airports', 'Unable to find the requested airport') + sys.exit(-1) airport = self.airports[airport][0] for key in config: @@ -127,7 +134,8 @@ class SctEseFormat: foundSidsStars = True if False == foundSidsStars: - raise FormatError('Unable to find SIDSSTARS-entries in the sector file') + sys.stderr.write('Unable to find SIDSSTARS-entries in the sector file') + sys.exit(-1) # parse all arrival routes for line in config['SIDSSTARS']: diff --git a/aman/types/Exception.py b/aman/types/Exception.py deleted file mode 100644 index 5e66b00..0000000 --- a/aman/types/Exception.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python - -class Error(Exception): - pass - -class FormatError(Error): - def __init__(self, message): - self.message = message - -class InputError(Error): - def __init__(self, expression, message): - self.expression = expression - self.message = message