Browse Source

Catch schema parsing errors.

Afshin Darian 7 years ago
parent
commit
c4b5b9bd7d
1 changed files with 10 additions and 4 deletions
  1. 10 4
      jupyterlab/settings_handler.py

+ 10 - 4
jupyterlab/settings_handler.py

@@ -24,13 +24,19 @@ class SettingsHandler(APIHandler):
     @json_errors
     @web.authenticated
     def get(self, section_name):
-        self.set_header("Content-Type", 'application/json')
-        path = os.path.join(self.schemas_dir, section_name + '.json')
+        self.set_header('Content-Type', "application/json")
+        path = os.path.join(self.schemas_dir, section_name + ".json")
 
         if not os.path.exists(path):
             raise web.HTTPError(404, "Schema not found: %r" % section_name)
         with open(path) as fid:
-            schema = json.load(fid)
+            # Attempt to load the schema file.
+            try:
+                schema = json.load(fid)
+            except Exception as e:
+                name = section_name
+                message = "Failed parsing schema ({}): {}".format(name, str(e))
+                raise web.HTTPError(500, message)
 
         path = os.path.join(self.settings_dir, section_name + '.json')
         settings = dict()
@@ -82,7 +88,7 @@ class SettingsHandler(APIHandler):
             os.makedirs(self.settings_dir)
 
         path = os.path.join(self.settings_dir, section_name + '.json')
-        
+
         with open(path, 'w') as fid:
             json.dump(data, fid)