From 68bd06cdcd3ca8254777582d6b1c3902056f695d Mon Sep 17 00:00:00 2001
From: Jye Cusch
Date: Thu, 8 Aug 2024 13:01:23 +1000
Subject: [PATCH 1/4] fix: update nitric server connection refused errors
Improves the description of the errors and removes a reference to the v0 `nitric start` command
---
nitric/application.py | 12 ++++++------
nitric/exception.py | 3 ++-
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/nitric/application.py b/nitric/application.py
index 366fed3..3fefc23 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 are 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):
From 1b3365ad3a573805c92d73825e316240ceff85b3 Mon Sep 17 00:00:00 2001
From: Jye Cusch
Date: Thu, 8 Aug 2024 13:05:04 +1000
Subject: [PATCH 2/4] chore: set correct min python version
---
.python-version | 2 +-
README.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
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 @@
-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.
From a6cd5a86a433a0470c63a1009dbf21ebb137c72f Mon Sep 17 00:00:00 2001
From: Jye Cusch
Date: Thu, 8 Aug 2024 13:12:12 +1000
Subject: [PATCH 3/4] Update nitric/application.py
Co-authored-by: Ryan Cartwright <39504851+HomelessDinosaur@users.noreply.github.com>
---
nitric/application.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/nitric/application.py b/nitric/application.py
index 3fefc23..44ca9eb 100644
--- a/nitric/application.py
+++ b/nitric/application.py
@@ -58,7 +58,7 @@ def _create_resource(cls, resource: Type[BT], name: str, *args: Any, **kwargs: A
return cls._cache[resource_type][name]
except ConnectionRefusedError as cre:
raise NitricUnavailableException(
- "The nitric server may not be running or the host/port are inaccessible"
+ "The nitric server may not be running or the host/port is inaccessible"
) from cre
@classmethod
From d1923dec76d20520b87a6e0ded1013ba5eb280ea Mon Sep 17 00:00:00 2001
From: Jye Cusch
Date: Fri, 9 Aug 2024 08:31:41 +1000
Subject: [PATCH 4/4] update test
---
tests/test_application.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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()