mu-semtech / mu-python-template

Template for running Python/Flask microservices
MIT License
4 stars 8 forks source link

Crashes from missing pip modules only return a 404 #12

Open Denperidge opened 1 year ago

Denperidge commented 1 year ago

Steps to recreate:

  1. Try to import a module that is not installed in web.py (or a file that gets imported from web.py)
  2. Run the service (this should happen in both prod or dev)

Output:

identifier_1  | 15:05:51.998 [info]  GET /repo-harvester/
identifier_1  | keeping user_id
dispatcher_1  | 
dispatcher_1  | 15:05:51.999 [info]  GET /repo-harvester
harvester_1   | 172.24.0.5 - - [24/May/2023 15:05:52] "GET / HTTP/1.1" 404 -
dispatcher_1  | 
dispatcher_1  | 15:05:52.004 [info]  Sent 404 in 4ms
identifier_1  | 
identifier_1  | 15:05:52.005 [info]  Sent 404 in 6ms
identifier_1  | 

If possible, a clearer error as to where the lack of functional routes comes from would be optimal

sergiofenoll commented 10 months ago

We should definitely handle this better.

I think the cause is that we're importing service code here, but failure to import (as you say because of a missing requirement but also because of syntax errors for example) doesn't cause the service to fail, Flask still sets up the app, just without any routes (that's why everything ends up returning a 404).

Would it be better to have the service not boot up at all if there's an error importing the service code? I'm not sure how such errors are handled in other templates.