diff --git a/.python-version b/.python-version index 56d91d3..afad818 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.10.12 +3.11.0 diff --git a/README.md b/README.md index 8f8d6a0..f153148 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Discord

-The Python SDK supports the use of the [Nitric](https://nitric.io) framework with Python 3.10+. For more information check out the main [Nitric repo](https://github.com/nitrictech/nitric). +The Python SDK supports the use of the [Nitric](https://nitric.io) framework with Python 3.11+. For more information check out the main [Nitric repo](https://github.com/nitrictech/nitric). Python SDKs provide an infrastructure-from-code style that lets you define resources in code. You can also write the functions that support the logic behind APIs, subscribers and schedules. diff --git a/nitric/application.py b/nitric/application.py index 366fed3..44ca9eb 100644 --- a/nitric/application.py +++ b/nitric/application.py @@ -56,10 +56,10 @@ def _create_resource(cls, resource: Type[BT], name: str, *args: Any, **kwargs: A cls._cache[resource_type][name] = resource.make(name, *args, **kwargs) # type: ignore return cls._cache[resource_type][name] - except ConnectionRefusedError: + except ConnectionRefusedError as cre: raise NitricUnavailableException( - 'Unable to connect to a nitric server! If you\'re running locally make sure to run "nitric start"' - ) from None + "The nitric server may not be running or the host/port is inaccessible" + ) from cre @classmethod def run(cls) -> None: @@ -78,7 +78,7 @@ def run(cls) -> None: except KeyboardInterrupt: print("\nexiting") - except ConnectionRefusedError: + except ConnectionRefusedError as cre: raise NitricUnavailableException( - 'Unable to connect to a nitric server! If you\'re running locally make sure to run "nitric start"' - ) from None + 'If you\'re running locally use "nitric start" or "nitric run" to start your application' + ) from cre diff --git a/nitric/exception.py b/nitric/exception.py index 60202d6..62f8b1b 100644 --- a/nitric/exception.py +++ b/nitric/exception.py @@ -153,7 +153,8 @@ class NitricResourceException(Exception): class NitricUnavailableException(Exception): """Unable to connect to a nitric server.""" - pass + def __init__(self, message: str): + super().__init__("Unable to connect to nitric server." + (" " + message if message else "")) def exception_from_grpc_error(error: GRPCError): diff --git a/tests/test_application.py b/tests/test_application.py index 09b11cb..9b8b21b 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -96,7 +96,7 @@ def test_run_with_connection_refused(self): application.run() pytest.fail() except NitricUnavailableException as e: - assert str(e).startswith("Unable to connect to a nitric server!") + assert str(e).startswith("Unable to connect to nitric server") mock_running_loop.assert_called_once() mock_event_loop.assert_not_called()