Skip to content
Snippets Groups Projects
Commit ecb841df authored by Sec 42's avatar Sec 42
Browse files

py/nick: handle errors in json

parent 19bf89ee
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ class Configuration: ...@@ -17,6 +17,7 @@ class Configuration:
self.pronouns_size: int = 25 self.pronouns_size: int = 25
self.color = "0x40ff22" self.color = "0x40ff22"
self.mode = 0 self.mode = 0
self._write = True
@classmethod @classmethod
def load(cls, path: str) -> "Configuration": def load(cls, path: str) -> "Configuration":
...@@ -27,6 +28,9 @@ class Configuration: ...@@ -27,6 +28,9 @@ class Configuration:
data = json.loads(jsondata) data = json.loads(jsondata)
except OSError: except OSError:
data = {} data = {}
except json.decoder.JSONDecodeError:
data = {"name": "json error"}
res._write = False
if "name" in data and type(data["name"]) == str: if "name" in data and type(data["name"]) == str:
res.name = data["name"] res.name = data["name"]
if "size" in data: if "size" in data:
...@@ -132,6 +136,7 @@ class NickApp(Application): ...@@ -132,6 +136,7 @@ class NickApp(Application):
# ctx.fill() # ctx.fill()
def on_exit(self) -> None: def on_exit(self) -> None:
if self._config._write:
self._config.save(self._filename) self._config.save(self._filename)
def think(self, ins: InputState, delta_ms: int) -> None: def think(self, ins: InputState, delta_ms: int) -> None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment