buggyrace / buggy-race-server

Race server and supporting material for running a "Buggy Racing" Python programming project
https://www.buggyrace.net
Other
1 stars 0 forks source link

Change app.py to log exceptions by default #233

Open mandyWW opened 5 months ago

mandyWW commented 5 months ago

Students are very to face errors when trying to add a new field to the database. It would be very helpful therefore if app.py could include the following so that exceptions are logged:

       except Exception as e: 
            print(e)
            con.rollback()
            msg = "error in update operation"
davewhiteland commented 4 months ago

Yes and no — the buggy editor does have an example of catching the exception here:

https://github.com/buggyrace/buggy-race-editor/blob/b8c9bc7fa90bcc34074b5b5b800878fca9c5d697/app.py#L39-L41

Furthermore I learned (the hard way of course, oops) that catching the base Exception is very counterproductive because it (correctly, but confusingly for newbies) catches their Python syntax errors too, which is why it's now the sql.IoperationalError there. Note also it's superhelpful that the message includes the exception text:

message = f"Error in update operation: {e}"

But (and it's quite a big but) it's hitherto been deliberate that those two methods (create...) and (show...) are not both handling the database accesses the same way: i.e., one provides good except catch, and the other none at all. Ultimately it comes down to just how correct the starting code should be — if we want all database operations to be handled the same way... should be a separate process that is called in call cases maybe.