Skip to content

Commit 43d7221

Browse files
authored
never raise ValueError - always use hyperframe custom types (#147)
1 parent 83538a7 commit 43d7221

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

HISTORY.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Release History
1616
- Fixed unchecked frame length for ``WindowUpdateFrame``. It now correctly raises ``InvalidFrameError``.
1717
- Fixed window increment value range validation. It must be 1 <= increment <= 2^31-1.
1818
- Fixed parsing of ``SettingsFrame`` with mutual exclusion of ACK flag and payload.
19+
- Invalid frames with wrong stream id (zero vs. non-zero) now raise ``InvalidFrameError``, not
20+
``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass.
21+
- Invalid SETTINGS frames (non-empty but ACK) now raise ``InvalidFrameError``, not
22+
``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass.
23+
- Invalid ALTSVC frames with non-bytestring field or origin now raise ``InvalidFrameError``, not
24+
``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass.
25+
1926

2027
**Other Changes**
2128

hyperframe/frame.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ def __init__(self, stream_id, flags=()):
6868

6969
if (not self.stream_id and
7070
self.stream_association == _STREAM_ASSOC_HAS_STREAM):
71-
raise ValueError('Stream ID must be non-zero')
71+
raise InvalidFrameError('Stream ID must be non-zero')
7272
if (self.stream_id and
7373
self.stream_association == _STREAM_ASSOC_NO_STREAM):
74-
raise ValueError('Stream ID must be zero')
74+
raise InvalidFrameError('Stream ID must be zero')
7575

7676
def __repr__(self):
7777
flags = ", ".join(self.flags) or "None"
@@ -415,7 +415,9 @@ def __init__(self, stream_id=0, settings=None, **kwargs):
415415
super(SettingsFrame, self).__init__(stream_id, **kwargs)
416416

417417
if settings and "ACK" in kwargs.get("flags", ()):
418-
raise ValueError("Settings must be empty if ACK flag is set.")
418+
raise InvalidFrameError(
419+
"Settings must be empty if ACK flag is set."
420+
)
419421

420422
#: A dictionary of the setting type byte to the value of the setting.
421423
self.settings = settings or {}
@@ -762,9 +764,9 @@ def __init__(self, stream_id, origin=b'', field=b'', **kwargs):
762764
super(AltSvcFrame, self).__init__(stream_id, **kwargs)
763765

764766
if not isinstance(origin, bytes):
765-
raise ValueError("AltSvc origin must be bytestring.")
767+
raise InvalidFrameError("AltSvc origin must be bytestring.")
766768
if not isinstance(field, bytes):
767-
raise ValueError("AltSvc field must be a bytestring.")
769+
raise InvalidFrameError("AltSvc field must be a bytestring.")
768770
self.origin = origin
769771
self.field = field
770772

0 commit comments

Comments
 (0)