Rymapt / ethoscope

a platform from monitoring animal behaviour in real time from a raspberry pi
http://gilestrolab.github.io/ethoscope/
GNU General Public License v3.0
0 stars 2 forks source link

Fix exception when database is empty #30

Open mark-grimes opened 7 years ago

mark-grimes commented 7 years ago

TL;DR: MySQLdbCSVWriter needs to handle cases where the database is empty.

I recently just got this error while testing database downloading:

ERROR:root:Error during DB download: (1146, "Table 'ethoscope_db.ROI_1' doesn't exist")
ERROR:root:Traceback (most recent call last):
  File "server.py", line 26, in func_wrapper
    return func(*args, **kwargs)
  File "server.py", line 297, in dynamic_serve_db
    for row in gen:
  File "/opt/ethoscope-git/node_src/ethoscope_node/utils/mysql_db_writer.py", line 125, in enumerate_roi_tables
    src_cur.execute(src_command)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'ethoscope_db.ROI_1' doesn't exist")

If I use MySQLWorkbench to check the DB, there are indeed no ROI_<n> tables at all. Pretty sure there were no tracking events, since I didn't insert an appendage while running, so it's reasonable that there are no tables. The code should be able to handle this, whether it be to just return nothing or produce a more meaningful error. Note that to get the stack trace above I had to write some extra code to trigger the error in ethoscope code - as the repository currently stands Bottle triggers the Exception and swallows all meaningful messages and just displays "Unhandled exception" on the webpage.