summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gps/client.py10
-rwxr-xr-xgpsfake3
2 files changed, 12 insertions, 1 deletions
diff --git a/gps/client.py b/gps/client.py
index b30ad858..541c5ae1 100644
--- a/gps/client.py
+++ b/gps/client.py
@@ -10,6 +10,11 @@ else:
GPSD_PORT="2947"
+class json_error:
+ def __init__(self, data, explanation):
+ self.data = data
+ self.explanation = explanation
+
class gpscommon:
"Isolate socket handling and buffering from the protcol interpretation."
def __init__(self, host="127.0.0.1", port=GPSD_PORT, verbose=0):
@@ -142,7 +147,10 @@ class gpsjson(gpscommon):
va = v
t[ka] = va
return t
- self.data = dictwrapper(**asciify(json.loads(buf.strip(), encoding="ascii")))
+ try:
+ self.data = dictwrapper(**asciify(json.loads(buf.strip(), encoding="ascii")))
+ except ValueError, e:
+ raise json_error(buf, e.args[0])
# Should be done for any other array-valued subobjects, too.
if self.data["class"] == "SKY" and hasattr(self.data, "satellites"):
self.data.satellites = map(lambda x: dictwrapper(**x), self.data.satellites)
diff --git a/gpsfake b/gpsfake
index 82874bca..7dfd5e06 100755
--- a/gpsfake
+++ b/gpsfake
@@ -195,6 +195,9 @@ if __name__ == '__main__':
except socket.error, msg:
sys.stderr.write("gpsfake: socket error %s.\n" % msg)
raise SystemExit, 1
+ except gps.client.json_error, e:
+ sys.stderr.write("gpsfake: JSON error on line %s is %s.\n" % (`e.data`, e.explanation))
+ raise SystemExit, 1
finally:
test.cleanup();