Skip to content

Commit 132609c

Browse files
Delegate dbapi _cap_raw_message to the wire-layer helper
The truncation logic + suffix wording moved to dqlitewire._truncate so the client and dbapi sides share a single source. The non-Optional return type is preserved for call-site type narrowness via an assert on the wire helper's None-only-on-None-input contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 478fc26 commit 132609c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/dqlitedbapi/exceptions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,17 @@ class Warning(Exception): # PEP 249 mandated class name
138138

139139

140140
def _cap_raw_message(raw_message: str) -> str:
141-
if len(raw_message) <= _MAX_RAW_MESSAGE:
142-
return raw_message
143-
overflow = len(raw_message) - _MAX_RAW_MESSAGE
144-
return raw_message[:_MAX_RAW_MESSAGE] + f"... [raw_message truncated, {overflow} codepoints]"
141+
# Thin wrapper over the wire-layer helper so the truncation logic
142+
# + suffix wording lives in one place. The non-Optional return is
143+
# preserved so call sites that already filtered out None don't
144+
# need a type-narrow.
145+
from dqlitewire._truncate import _cap_raw_message as _wire_cap
146+
147+
capped = _wire_cap(raw_message, _MAX_RAW_MESSAGE)
148+
# ``_wire_cap`` returns ``None`` only when the input is ``None``;
149+
# this caller passes ``str`` so the narrow is safe.
150+
assert capped is not None
151+
return capped
145152

146153

147154
class Error(Exception):

0 commit comments

Comments
 (0)