diff --git a/src/wsproto/frame_protocol.py b/src/wsproto/frame_protocol.py index d13a769..fcb8a13 100644 --- a/src/wsproto/frame_protocol.py +++ b/src/wsproto/frame_protocol.py @@ -574,7 +574,7 @@ def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> byt if code is None and reason: raise TypeError("cannot specify a reason without a code") if code in LOCAL_ONLY_CLOSE_REASONS: - code = CloseReason.NORMAL_CLOSURE + raise ValueError(f"cannot specify a local-only close code, got {code}") if code is not None: payload += bytearray(struct.pack("!H", code)) if reason is not None: diff --git a/test/test_frame_protocol.py b/test/test_frame_protocol.py index 76c40e4..aef85c5 100644 --- a/test/test_frame_protocol.py +++ b/test/test_frame_protocol.py @@ -1043,8 +1043,8 @@ def test_no_status_rcvd_close_reason(self) -> None: def test_local_only_close_reason(self) -> None: proto = fp.FrameProtocol(client=False, extensions=[]) - data = proto.close(code=fp.CloseReason.ABNORMAL_CLOSURE) - assert data == b"\x88\x02\x03\xe8" + with pytest.raises(ValueError): + proto.close(code=fp.CloseReason.ABNORMAL_CLOSURE) def test_ping_without_payload(self) -> None: proto = fp.FrameProtocol(client=False, extensions=[])