Description
When using litestar run with application lookup through a directory (e.g. the CWD), and an ImportError happens, you get a normal traceback, showing exactly what is going on. However, if you instead import the app through the environment, as litestar --app "app_module:app" run, and any kind of ImportError happens, the only thing you get is this:
Using Litestar app from env: 'app_module:app'
Invalid argument passed --app 'app_module:app': Module not found
In particular, this misleadingly seems to suggests that app_module cannot be found. In reality, you get the same error message no matter which module caused the ImportError. This issue is exacerbated by the fact that these errors typically happen due to a packaging problem, which often is only identified in CI testing or the staging environment, where direct analysis of the issue is not possible.
URL to code causing the issue
No response
MCVE
from litestar import Litestar, get
# the following module does not exist, highlighting an ImportError with a dependency.
import does_not_exist
@get("/")
async def hello_world() -> dict[str, str]:
"""Handler function that returns a greeting dictionary."""
return {"hello": "world"}
app = Litestar(route_handlers=[hello_world])
Steps to reproduce
- Put the above MCVE into a file
app_module.py
cd into that directory.
- Run
litestar --app app_module:app run (ensure that litestar is installed).
- See error
Screenshots
No response
Logs
Using Litestar app from env: 'app_module:app'
Invalid argument passed --app 'app_module:app': Module not found
Litestar Version
2.15.2
Platform
Description
When using
litestar runwith application lookup through a directory (e.g. the CWD), and anImportErrorhappens, you get a normal traceback, showing exactly what is going on. However, if you instead import the app through the environment, aslitestar --app "app_module:app" run, and any kind ofImportErrorhappens, the only thing you get is this:In particular, this misleadingly seems to suggests that
app_modulecannot be found. In reality, you get the same error message no matter which module caused theImportError. This issue is exacerbated by the fact that these errors typically happen due to a packaging problem, which often is only identified in CI testing or the staging environment, where direct analysis of the issue is not possible.URL to code causing the issue
No response
MCVE
Steps to reproduce
app_module.pycdinto that directory.litestar --app app_module:app run(ensure thatlitestaris installed).Screenshots
No response
Logs
Litestar Version
2.15.2
Platform