summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-08-22 10:43:46 +0200
committerSanto Cariotti <sancn@live.com>2017-08-22 10:43:46 +0200
commita9734c6146b6588244406578930cd4f0a061ad4c (patch)
treeeec168a5d7892d6d64357532f6ecf166c7f57ae7
parent8ee6331c0e8105134c0ac29cd4fceecd2968f89b (diff)
fixed exceptions
-rw-r--r--lib/.commands.py.swpbin0 -> 16384 bytes
-rw-r--r--lib/app.py4
-rw-r--r--lib/commands.py26
-rw-r--r--lib/listcommands.py4
4 files changed, 13 insertions, 21 deletions
diff --git a/lib/.commands.py.swp b/lib/.commands.py.swp
new file mode 100644
index 0000000..d80ed53
--- /dev/null
+++ b/lib/.commands.py.swp
Binary files differ
diff --git a/lib/app.py b/lib/app.py
index c5d68ec..1a74485 100644
--- a/lib/app.py
+++ b/lib/app.py
@@ -53,14 +53,14 @@ class Stout(Commands):
else:
raise KeyError
except (KeyError, IndexError):
- ListCommands.err('keyword')
+ ListCommands.err('KeyError')
else:
try:
what = cmd[0]
if what in ListCommands.commands:
self.command(what, cmd)
else:
- ListCommands.err('keyword')
+ ListCommands.err('KeyError')
except IndexError:
pass
diff --git a/lib/commands.py b/lib/commands.py
index db464fe..ced0f3c 100644
--- a/lib/commands.py
+++ b/lib/commands.py
@@ -24,10 +24,8 @@ class Commands(object):
print('Ok')
elif cmd[1] is not ListCommands.commands['set']:
raise KeyError
- except IndexError:
- ListCommands.err('wrong')
- except KeyError:
- ListCommands.err('keyword')
+ except (IndexError, KeyError) as e:
+ ListCommands.err(type(e).__name__)
except PersonalError as e:
ListCommands.err('personal', e.value)
elif what == 'get':
@@ -43,7 +41,7 @@ class Commands(object):
else:
print('nil')
elif cmd[2] not in ListCommands.commands['get'][1]: #check if the word after 'i' exists
- ListCommands.err('keyword')
+ raise KeyError
else:
print(co[cmd[2]])
elif cmd[1] == 'todo':
@@ -63,10 +61,8 @@ class Commands(object):
print(count.decode('utf-8'))
else:
raise KeyError
- except IndexError:
- ListCommands.err('wrong')
- except KeyError:
- ListCommands.err('keyword')
+ except (IndexError, KeyError) as e:
+ ListCommands.err(type(e).__name__)
except PersonalError as e:
ListCommands.err('personal', e.value)
elif what == 'add':
@@ -84,10 +80,8 @@ class Commands(object):
print('Ok')
except:
raise KeyError
- except IndexError:
- ListCommands.err('wrong')
- except KeyError:
- ListCommands.err('keyword')
+ except (IndexError, KeyError):
+ ListCommands.err(type(e).__name__)
elif what == 'del':
try:
if len(cmd) > ListCommands.info['del'][1]:
@@ -105,10 +99,8 @@ class Commands(object):
print('Ok')
except Exception as e:
print(e)
- except IndexError:
- ListCommands.err('wrong')
- except KeyError:
- ListCommands.err('keyword')
+ except (IndexError, KeyError) as e:
+ ListCommands.err(type(e).__name__)
def msgFromId(value):
diff --git a/lib/listcommands.py b/lib/listcommands.py
index 987aeb5..869f475 100644
--- a/lib/listcommands.py
+++ b/lib/listcommands.py
@@ -27,9 +27,9 @@ Se utilizzato con il "flag" i, si possono visualizzare le info: get i host, get
@staticmethod
def err(err, info = ''):
- if err == 'keyword':
+ if err == 'KeyError':
sys.stderr.write(RED + 'keyword inesistente\n' + BLACK)
- elif err == 'wrong':
+ elif err == 'IndexError':
sys.stderr.write(RED + 'sintassi comando errata\n' + BLACK)
elif err == 'personal':
sys.stderr.write(RED + str(info) + '\n' + BLACK)