diff --git a/HISTORY.rst b/HISTORY.rst index 5393968..7695a20 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,16 @@ Release History =============== +dev +--- + +**API Changes (Backward-compatible)** + +- Invalid PING frame bodies now raise ``InvalidFrameError``, not + ``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass. +- Invalid RST_STREAM frame bodies now raise ``InvalidFramError``, not + ``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass. + 3.1.1 (2016-01-18) ------------------ diff --git a/hyperframe/frame.py b/hyperframe/frame.py index 00c2b97..1c54d18 100644 --- a/hyperframe/frame.py +++ b/hyperframe/frame.py @@ -310,7 +310,10 @@ def serialize_body(self): def parse_body(self, data): if len(data) != 4: - raise ValueError() + raise InvalidFrameError( + "RST_STREAM must have 4 byte body: actual length %s." % + len(data) + ) try: self.error_code = struct.unpack("!L", data)[0] @@ -461,7 +464,10 @@ def __init__(self, stream_id=0, opaque_data=b'', **kwargs): def serialize_body(self): if len(self.opaque_data) > 8: - raise ValueError() + raise InvalidFrameError( + "PING frame may not have more than 8 bytes of data, got %s" % + self.opaque_data + ) data = self.opaque_data data += b'\x00' * (8 - len(self.opaque_data)) @@ -469,7 +475,9 @@ def serialize_body(self): def parse_body(self, data): if len(data) != 8: - raise ValueError() + raise InvalidFrameError( + "PING frame must have 8 byte length: got %s" % len(data) + ) self.opaque_data = data.tobytes() self.body_len = len(data)