kovidgoyal/kitty · warning
Malformed OSC 5522: metadata is not key=value pairs
Error message
Malformed OSC 5522: metadata is not key=value pairs
What it means
An OSC 5522 clipboard control sequence's metadata section could not be split into key=value records; kitty logs and drops the whole message.
Source
Thrown at kitty/clipboard.py:399
self.osc52_in_flight_write_requests: dict[ClipboardType, WriteRequest] = {}
self.granted_passwords: dict[str, GrantedPermission] = {}
def parse_osc_5522(self, data: memoryview) -> None:
from .notifications import sanitize_id
idx = find_in_memoryview(data, ord(b';'))
if idx > -1:
metadata = str(data[:idx], 'utf-8', 'replace')
epayload = data[idx + 1 :]
else:
metadata = str(data, 'utf-8', 'replace')
epayload = data[len(data) :]
m: dict[str, str] = {}
for record in metadata.split(':'):
try:
k, v = record.split('=', 1)
except Exception:
log_error('Malformed OSC 5522: metadata is not key=value pairs')
return
m[k] = v
typ = m.get('type', '')
try:
m = {k: decode_metadata_value(k, v) for k, v in m.items()}
except Exception as e:
log_error(f'Malformed OSC 5522: could not decode a metadata value. Error: {e}')
if typ in ('wdata', 'walias') and self.in_flight_write_request is not None:
self.abort_write_request(self.in_flight_write_request, 'EINVAL')
return
if typ == 'read':
try:
mime_types = tuple(strict_base64_decode(epayload).decode('utf-8').split())
except Exception as e:
log_error(f'Malformed OSC 5522: read request payload is not valid base64 encoded UTF-8. Error: {e}')
return
rr = ReadRequest(
is_primary_selection=m.get('loc', '') == 'primary',View on GitHub (pinned to 6d5d0c4406)
Solutions
- Fix the client to use '=' between key and value, ':' between records
- Send well-formed OSC 5522: metadata records like type=wdata:loc=clipboard
Example fix
# before \x1b]5522;type:wdata\x1b\\ # after \x1b]5522;type=wdata\x1b\\
Defensive patterns
Strategy: validation
Validate before calling
def valid_meta(metadata: str) -> bool:
return all('=' in rec for rec in metadata.split(':')) Prevention
- Use '=' for key=value and ':' as record separator in OSC 5522 metadata
- Test protocol encodings against kitty's docs before shipping
When it happens
Trigger: parse_osc_5522 receives metadata where a record lacks '=' (e.g. 'type:wdata' instead of 'type=wdata'), so record.split('=',1) fails to unpack.
Common situations: Hand-rolled clients or probes of the kitty clipboard protocol using ':' as the kv separator instead of '='; truncated sequences.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Malformed OSC 5522: could not decode a metadata value. Error
- Clipboard alias request has no MIME type, aborting the write
- not a valid file descriptor number: %#v
- %s
- %s is not valid MIME alias specification
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/146033bfb0fe3a8d.
Report an issue: GitHub.