Skip to content

Commit

Permalink
Fix parsing of garbage input to get_event_ids (#45)
Browse files Browse the repository at this point in the history
* Replace ProtocolError with RetryError in get_event_ids
* Improve replacement of exception
  • Loading branch information
hmpf authored Jan 26, 2024
1 parent e00f8b9 commit eb0409f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/zinolib/controllers/zino1.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
from ..compat import StrEnum
from ..event_types import EventType, Event, HistoryEntry, LogEntry, AdmState
from ..event_types import PortStateEvent
from ..ritz import ZinoError, ritz, notifier
from ..ritz import ZinoError, ProtocolError, ritz, notifier
from ..utils import log_exception_with_params


Expand Down Expand Up @@ -297,7 +297,10 @@ def set_admin_state(request, event: EventType, state: AdmState) -> bool:

@staticmethod
def get_event_ids(request):
return request.get_caseids()
try:
return request.get_caseids()
except ProtocolError as e:
raise RetryError('Zino 1 failed to send a correct response header, retry') from e


class HistoryAdapter:
Expand Down Expand Up @@ -400,7 +403,7 @@ def parse_response(log_data: Iterable[str]) -> list[LogDict]:
try:
timestamp = int(timestamp)
except ValueError as e:
raise RetryError('Zino 1 is flaking out, retry') from e
raise RetryError('Zino 1 did not send a log, retry') from e
dt = convert_timestamp(timestamp)
log_list.append({"date": dt, "log": log})
return log_list
Expand Down Expand Up @@ -485,7 +488,7 @@ def create_event_from_id(self, event_id: int):
self._verify_session()
attrlist = self.rename_exception(self._event_adapter.get_attrlist, self.session.request, event_id)
if not self._event_adapter.validate_raw_attrlist(attrlist):
raise RetryError('Zino 1 is flaking out, retry')
raise RetryError('Zino 1 did not send event attributes, retry')
attrdict = self._event_adapter.attrlist_to_attrdict(attrlist)
attrdict = self._event_adapter.convert_values(attrdict)
return Event.create(attrdict)
Expand Down
4 changes: 2 additions & 2 deletions src/zinolib/ritz.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ def _request(self, command: bytes, recv_buffer=4096, **_):
line, buffer = buffer.split(self.DELIMITER, 1)
rawh = line.split(" ", 1) # ' ' is not a byte
header = (int(rawh[0]), rawh[1])
except ValueError:
except ValueError as e:
raise ProtocolError(
"Illegal response from server detected: %s" % repr(buffer)
)
) from e
# header = line
# Crude error detection :)
if header[0] >= 500:
Expand Down

0 comments on commit eb0409f

Please sign in to comment.