From 9894af021e40ee01a99d1a06f7088861eab5205a Mon Sep 17 00:00:00 2001 From: example Date: Sun, 10 Oct 2021 23:34:24 +0200 Subject: [PATCH] add error handling for argument and class creation --- source/server/setstatus.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/server/setstatus.py b/source/server/setstatus.py index f62a2e3..fc615be 100755 --- a/source/server/setstatus.py +++ b/source/server/setstatus.py @@ -60,6 +60,11 @@ class SetStatus: """ return: boolean """ + try: + self.status = int(self.status) + except Exception as e: + self.log.error('Status argument does not represent a integer') + return False if self.status in (0, 1): self.log.debug('Set value to {}'.format(self.status)) self.status = bytes([self.status]) @@ -233,3 +238,12 @@ class SetStatus: self.log.error('Error: {}'.format(e)) exit(7) + +if __name__ == '__main__': + s = SetStatus() + if len(argv) < 2: + log.error('Usage: setstatus.py <0|1>') + exit(255) + else: + s.run(argv[1]) +