improve error message if no apps found in registry (#2585)

This commit is contained in:
Santi Cardozo 2022-10-25 15:54:44 +02:00 committed by GitHub
parent 97f33f42df
commit 6b9edfd05c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -1453,7 +1453,14 @@ class Sanic(BaseSanic, StartupMixin, metaclass=TouchUpMeta):
return cls.get_app("__mp_main__", force_create=force_create) return cls.get_app("__mp_main__", force_create=force_create)
if force_create: if force_create:
return cls(name) 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 @classmethod
def _check_uvloop_conflict(cls) -> None: def _check_uvloop_conflict(cls) -> None:

View File

@ -347,7 +347,13 @@ def test_app_registry_retrieval_from_multiple():
def test_get_app_does_not_exist(): def test_get_app_does_not_exist():
with pytest.raises( 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") Sanic.get_app("does-not-exist")