Skip to content

Commit

Permalink
improve error message if no apps found in registry (#2585)
Browse files Browse the repository at this point in the history
  • Loading branch information
scardozos committed Oct 25, 2022
1 parent 97f33f4 commit 6b9edfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,14 @@ def get_app(
return cls.get_app("__mp_main__", force_create=force_create)
if force_create:
return cls(name)
raise SanicException(f'Sanic app name "{name}" not found.')
raise SanicException(
f"Sanic app name '{name}' not found.\n"
"App instantiation must occur outside "
"if __name__ == '__main__' "
"block or by using an AppLoader.\nSee "
"https://sanic.dev/en/guide/deployment/app-loader.html"
" for more details."
)

@classmethod
def _check_uvloop_conflict(cls) -> None:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,13 @@ def test_app_registry_retrieval_from_multiple():

def test_get_app_does_not_exist():
with pytest.raises(
SanicException, match='Sanic app name "does-not-exist" not found.'
SanicException,
match="Sanic app name 'does-not-exist' not found.\n"
"App instantiation must occur outside "
"if __name__ == '__main__' "
"block or by using an AppLoader.\nSee "
"https://sanic.dev/en/guide/deployment/app-loader.html"
" for more details."
):
Sanic.get_app("does-not-exist")

Expand Down

0 comments on commit 6b9edfd

Please sign in to comment.