Skip to content

Commit

Permalink
replacing exception report to string
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Palaia authored and Daniele Palaia committed Oct 19, 2023
1 parent 9b23b21 commit 76a44d2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def on_connection_closed(disconnection_info: DisconnectionErrorInfo) -> No
"connection has been closed from stream: "
+ str(disconnection_info.streams)
+ " for reason: "
+ str(disconnection_info.reason)
+ disconnection_info.reason
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def on_connection_closed(disconnection_info: DisconnectionErrorInfo) -> No
"connection has been closed from stream: "
+ str(disconnection_info.streams)
+ " for reason: "
+ str(disconnection_info.reason)
+ disconnection_info.reason
)

global connection_is_closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def on_connection_closed(disconnection_info: DisconnectionErrorInfo) -> No
"connection has been closed from stream: "
+ str(disconnection_info.streams)
+ " for reason: "
+ str(disconnection_info.reason)
+ disconnection_info.reason
)

# clean close or reconnect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ async def on_message(msg: AMQPMessage, message_context: MessageContext):
print("Received message: {} from stream: {} - message offset: {}".format(msg, stream, offset))


async def on_connection_closed(disconnection_info: DisconnectionErrorInfo) -> None:
print(
"connection has been closed from stream: "
+ str(disconnection_info.streams)
+ " for reason: "
+ str(disconnection_info.reason)
)


async def consume():
async def on_connection_closed(disconnection_info: DisconnectionErrorInfo) -> None:
print(
"connection has been closed from stream: "
+ str(disconnection_info.streams)
+ " for reason: "
+ disconnection_info.reason
)
await consumer.close()

consumer = SuperStreamConsumer(
host="localhost",
port=5552,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def on_connection_closed(disconnection_info: DisconnectionErrorInfo) -> No
"connection has been closed from stream: "
+ str(disconnection_info.streams)
+ " for reason: "
+ str(disconnection_info.reason)
+ disconnection_info.reason
)
global connection_is_closed
connection_is_closed = True
Expand Down
14 changes: 7 additions & 7 deletions rstream/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ async def send_frame(self, frame: schema.Frame) -> None:
assert self._conn
try:
await self._conn.write_frame(frame)
except socket.error as e:
except socket.error:
self._is_not_closed = False
if self._connection_closed_handler is None:
logger.exception("TCP connection closed")
else:
connection_error_info = DisconnectionErrorInfo(e, self._streams)
connection_error_info = DisconnectionErrorInfo("Socket Error", self._streams)
result = self._connection_closed_handler(connection_error_info)
if result is not None and inspect.isawaitable(result):
await result
Expand Down Expand Up @@ -215,10 +215,10 @@ async def _listener(self) -> None:
try:
if self.is_connection_alive():
frame = await self._conn.read_frame()
except ConnectionClosed as e:
except ConnectionClosed:

if self._connection_closed_handler is not None and self.is_connection_alive():
connection_error_info = DisconnectionErrorInfo(e, self._streams)
connection_error_info = DisconnectionErrorInfo("Connection Closed", self._streams)
result = self._connection_closed_handler(connection_error_info)
if result is not None and inspect.isawaitable(result):
await result
Expand All @@ -227,15 +227,15 @@ async def _listener(self) -> None:

self._is_not_closed = False
break
except socket.error as e:
except socket.error:
if self._conn is not None:
if self._connection_closed_handler is not None and self.is_connection_alive():
connection_error_info = DisconnectionErrorInfo(e, self._streams)
connection_error_info = DisconnectionErrorInfo("Socket Error", self._streams)
result = self._connection_closed_handler(connection_error_info)
if result is not None and inspect.isawaitable(result):
await result
else:
print("TCP connection closed")
logger.debug("TCP connection closed")
self._is_not_closed = False
break

Expand Down
2 changes: 1 addition & 1 deletion rstream/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ def __await__(self) -> Generator[Any, None, Any]:

@dataclass
class DisconnectionErrorInfo:
reason: Exception
reason: str
streams: list[str]

0 comments on commit 76a44d2

Please sign in to comment.