Browse Source

replace exceptions by error messages

Sven Czarnian 3 years ago
parent
commit
d60d5cb716
2 changed files with 18 additions and 23 deletions
  1. 18 10
      aman/formats/SctEseFormat.py
  2. 0 13
      aman/types/Exception.py

+ 18 - 10
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']:

+ 0 - 13
aman/types/Exception.py

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