From 6b9edfd05cbe3dd13136d1ad97a248dd5f8751dd Mon Sep 17 00:00:00 2001 From: Santi Cardozo <57201631+scardozos@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:54:44 +0200 Subject: [PATCH] improve error message if no apps found in registry (#2585) --- sanic/app.py | 9 ++++++++- tests/test_app.py | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index cb6f76b3..e064f70f 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -1453,7 +1453,14 @@ class Sanic(BaseSanic, StartupMixin, metaclass=TouchUpMeta): 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: diff --git a/tests/test_app.py b/tests/test_app.py index 0e71f9f7..538fb893 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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")