Skip to content

Commit

Permalink
fix: update nitric server connection refused errors (#144)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jyecusch and HomelessDinosaur authored Aug 8, 2024
1 parent b4d9c27 commit 43cd4e1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.12
3.11.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<a href="https://nitric.io/chat"><img alt="Discord" src="https://img.shields.io/discord/955259353043173427?label=discord&style=for-the-badge"></a>
</p>

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.

Expand Down
12 changes: 6 additions & 6 deletions nitric/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
3 changes: 2 additions & 1 deletion nitric/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 43cd4e1

Please sign in to comment.