Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__main__ top-level script shadowing ImportError #665

Closed
pyx opened this issue Apr 27, 2017 · 0 comments
Closed

__main__ top-level script shadowing ImportError #665

pyx opened this issue Apr 27, 2017 · 0 comments

Comments

@pyx
Copy link
Contributor

pyx commented Apr 27, 2017

Given main.py:

import nonexistent  # assuming this is... non-existent
from sanic import Sanic, response


app = Sanic(__name__)


@app.route('/')
async def index(request):
    return response.html('<p>Hello</p>')

When we try to import something non-existent, exception ImportError will be thrown,
line 38 of main.py does not preserve the exception, reporting preset message (what's provided on commandline) instead. This is what we will get:

python -m sanic main.app
No module named main found.
  Example File: project/sanic_server.py -> app
  Example Module: project.sanic_server.app

It is very hard to find the true cause if the import statement that failed is, let's say, buried three levels of modules deep, for example.

@r0fls r0fls closed this as completed in ade89ab Apr 27, 2017
r0fls added a commit that referenced this issue Apr 27, 2017
Fix #665 - ImportError not preserved in __main__.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant