Skip to content

Commit

Permalink
utils/kamctl: fix handling of Exceptions
Browse files Browse the repository at this point in the history
> Traceback (most recent call last):
>   File "/usr/lib/x86_64-linux-gnu/kamailio/kamctl/dbtextdb/dbtextdb.py", line 1239, in <module>
>     main(sys.argv)
>   File "/usr/lib/x86_64-linux-gnu/kamailio/kamctl/dbtextdb/dbtextdb.py", line 1233, in main
>     except (Error, e):
> NameError: name 'e' is not defined

(cherry picked from commit 1aca79c)
(cherry picked from commit 5f6f433)
  • Loading branch information
linuxmaniac committed May 4, 2020
1 parent fb93749 commit 23062ed
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions utils/kamctl/dbtextdb/dbtextdb.py
Expand Up @@ -356,7 +356,7 @@ def _EscapeChars(self, value):
# test that the value is string, if not return it as is
try:
value.find('a')
except:
except Exception:
return value

escaped = value
Expand All @@ -377,7 +377,7 @@ def _UnEscapeChars(self, value):
# test that the value is string, if not return it as is
try:
value.find('a')
except:
except Exception:
return value

escaped = value
Expand Down Expand Up @@ -988,21 +988,19 @@ def _TypeCheck(self, val, col):
if not val and not self.header[col]['null']:
raise ExecuteError(col + ' cannot be empty or null')

if (self.header[col]['type'].lower() == 'int' or
self.header[col]['type'].lower() == 'double'):
hdr_t = self.header[col]['type'].lower()
if hdr_t == 'int' or hdr_t == 'double':
try:
if val:
val = eval(val)
except (NameError, e):
except NameError as e:
raise ExecuteError('Failed to parse %s in %s '
'(unable to convert to type %s): %s' %
(col, self.table, self.header[col]['type'],
e))
except (SyntaxError, e):
(col, self.table, hdr_t, e))
except SyntaxError as e:
raise ExecuteError('Failed to parse %s in %s '
'(unable to convert to type %s): %s' %
(col, self.table, self.header[col]['type'],
e))
(col, self.table, hdr_t, e))

return val

Expand Down Expand Up @@ -1083,7 +1081,7 @@ def OpenTable(self):
# save a copy of the data before modifying
self.orig_data = self.data[:]

except (IOError, e):
except IOError as e:
raise ExecuteError('Unable to open table %s: %s' % (self.table, e))

Debug('Header is: %s' % self.header)
Expand Down Expand Up @@ -1230,7 +1228,7 @@ def main(argv):
print('Updated %s, rows affected: %d' % (conn.table, row))
else:
print(row)
except (Error, e):
except Error as e:
print(e)
sys.exit(1)

Expand Down

0 comments on commit 23062ed

Please sign in to comment.