Skip to content

Commit 43cd4e1

Browse files
fix: update nitric server connection refused errors (#144)
Improves the description of the errors and removes a reference to the v0 `nitric start` command set correct min python version Co-authored-by: Ryan Cartwright <39504851+HomelessDinosaur@users.noreply.github.com>
1 parent b4d9c27 commit 43cd4e1

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.10.12
1+
3.11.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<a href="https://nitric.io/chat"><img alt="Discord" src="https://img.shields.io/discord/955259353043173427?label=discord&style=for-the-badge"></a>
2323
</p>
2424

25-
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).
25+
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).
2626

2727
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.
2828

nitric/application.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def _create_resource(cls, resource: Type[BT], name: str, *args: Any, **kwargs: A
5656
cls._cache[resource_type][name] = resource.make(name, *args, **kwargs) # type: ignore
5757

5858
return cls._cache[resource_type][name]
59-
except ConnectionRefusedError:
59+
except ConnectionRefusedError as cre:
6060
raise NitricUnavailableException(
61-
'Unable to connect to a nitric server! If you\'re running locally make sure to run "nitric start"'
62-
) from None
61+
"The nitric server may not be running or the host/port is inaccessible"
62+
) from cre
6363

6464
@classmethod
6565
def run(cls) -> None:
@@ -78,7 +78,7 @@ def run(cls) -> None:
7878
except KeyboardInterrupt:
7979

8080
print("\nexiting")
81-
except ConnectionRefusedError:
81+
except ConnectionRefusedError as cre:
8282
raise NitricUnavailableException(
83-
'Unable to connect to a nitric server! If you\'re running locally make sure to run "nitric start"'
84-
) from None
83+
'If you\'re running locally use "nitric start" or "nitric run" to start your application'
84+
) from cre

nitric/exception.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ class NitricResourceException(Exception):
153153
class NitricUnavailableException(Exception):
154154
"""Unable to connect to a nitric server."""
155155

156-
pass
156+
def __init__(self, message: str):
157+
super().__init__("Unable to connect to nitric server." + (" " + message if message else ""))
157158

158159

159160
def exception_from_grpc_error(error: GRPCError):

tests/test_application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_run_with_connection_refused(self):
9696
application.run()
9797
pytest.fail()
9898
except NitricUnavailableException as e:
99-
assert str(e).startswith("Unable to connect to a nitric server!")
99+
assert str(e).startswith("Unable to connect to nitric server")
100100

101101
mock_running_loop.assert_called_once()
102102
mock_event_loop.assert_not_called()

0 commit comments

Comments
 (0)