replace exceptions by error messages

This commit is contained in:
Sven Czarnian
2021-09-02 19:35:20 +02:00
parent b3b5b3e547
commit d60d5cb716
2 changed files with 18 additions and 23 deletions

View File

@@ -3,7 +3,6 @@
import sys import sys
from aman.types.ArrivalRoute import ArrivalRoute from aman.types.ArrivalRoute import ArrivalRoute
from aman.types.Exception import FormatError, InputError
from aman.types.Waypoint import Waypoint from aman.types.Waypoint import Waypoint
class SctEseFormat: class SctEseFormat:
@@ -29,7 +28,8 @@ class SctEseFormat:
def parseWaypoint(waypoint : str, nameIdx : int, latitudeIdx : int, longitudeIdx : int): def parseWaypoint(waypoint : str, nameIdx : int, latitudeIdx : int, longitudeIdx : int):
split = list(filter(None, waypoint.split(' '))) split = list(filter(None, waypoint.split(' ')))
if len(split) <= longitudeIdx: 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])) return Waypoint(split[nameIdx], Waypoint.dms2dd(split[latitudeIdx]), Waypoint.dms2dd(split[longitudeIdx]))
def extractWaypoints(self, sctFilepath : str): def extractWaypoints(self, sctFilepath : str):
@@ -50,13 +50,17 @@ class SctEseFormat:
foundAirports = True foundAirports = True
if False == foundVOR: 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: 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: 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: 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 # extract all waypoints
for waypoint in config['VOR']: for waypoint in config['VOR']:
@@ -88,7 +92,8 @@ class SctEseFormat:
coordinates = self.waypoints[waypoint] coordinates = self.waypoints[waypoint]
# no waypoint with this name defined # no waypoint with this name defined
if None == coordinates: 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 # multiple waypoints, but use Haversine distance to distinct between candidates
elif 1 != len(coordinates): elif 1 != len(coordinates):
minDistance = sys.float_info.max minDistance = sys.float_info.max
@@ -103,7 +108,8 @@ class SctEseFormat:
nearest = coordinate nearest = coordinate
if None == nearest: 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) waypoints.append(nearest)
# extend the list of waypoints # extend the list of waypoints
@@ -119,7 +125,8 @@ class SctEseFormat:
# search the airport in the extracted list # search the airport in the extracted list
if not airport in self.airports: 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] airport = self.airports[airport][0]
for key in config: for key in config:
@@ -127,7 +134,8 @@ class SctEseFormat:
foundSidsStars = True foundSidsStars = True
if False == foundSidsStars: 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 # parse all arrival routes
for line in config['SIDSSTARS']: for line in config['SIDSSTARS']:

View File

@@ -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