larksuite/cli · warning
odd hex length
Error message
odd hex length
What it means
decodeHex in the doc clipboard helper expects the «data XXXX<hex>» literal emitted by macOS osascript, whose hex payload always has even length. When the clipboard payload inside that wrapper has an odd number of hex characters, it cannot be split into byte pairs, so decoding fails. This is an internal intermediate error; callers discard the result and fall back to treating the data as non-image content.
Source
Thrown at shortcuts/doc/clipboard.go:193
const prefix = "\xc2\xab" + "data " // « in UTF-8 followed by "data "
if !strings.HasPrefix(s, prefix) {
// plain string — return as-is
return []byte(s), nil
}
// strip «data XXXX (4-char class code follows immediately, no space) and trailing »
s = s[len(prefix):]
if len(s) >= 4 {
s = s[4:] // skip class code, e.g. "HTML", "TIFF", "PNGf"
}
s = strings.TrimSuffix(s, "\xc2\xbb") // »
s = strings.TrimSpace(s)
return decodeHex(s)
}
// decodeHex decodes an uppercase hex string (as produced by osascript) to bytes.
func decodeHex(h string) ([]byte, error) {
if len(h)%2 != 0 {
return nil, fmt.Errorf("odd hex length") //nolint:forbidigo // intermediate decode helper; result discarded by caller on error
}
b := make([]byte, len(h)/2)
for i := 0; i < len(h); i += 2 {
hi := hexVal(h[i])
lo := hexVal(h[i+1])
if hi < 0 || lo < 0 {
return nil, fmt.Errorf("invalid hex char at %d", i) //nolint:forbidigo // intermediate decode helper; result discarded by caller on error
}
b[i/2] = byte(hi<<4 | lo)
}
return b, nil
}
func hexVal(c byte) int {
switch {
case c >= '0' && c <= '9':
return int(c - '0')
case c >= 'a' && c <= 'f':View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Copy the image again (or re-take the screenshot) so macOS writes a fresh, complete clipboard payload.
- Check the clipboard for text masquerading as an osascript data literal; paste it into a text editor to inspect and clear it.
- Retry the command; if it persists, clear the clipboard (e.g. pbcopy < /dev/null) and repeat the copy operation.
Defensive patterns
Strategy: fallback
Validate before calling
// Before pasting/uploading, sanity-check the copied content is a real image: file=$(osascript -e 'clipboard info' | grep -o '«class PNGf»' ) || echo 'clipboard does not hold image data'
Type guard
func looksLikeHexPairPayload(s string) bool { return len(s)%2 == 0 && len(s) > 0 } Try / catch
// The command already falls back internally; at the shell level, retry after recopying: if ! lark-cli doc import --clipboard; then echo "clipboard payload not an image; recopy the image and retry" >&2 fi
Prevention
- Copy actual images, not text snippets containing «data ...» literals.
- Clear the clipboard before capturing a new screenshot on macOS.
- Avoid clipboard managers that transform or truncate binary clipboard classes.
When it happens
Trigger: macOS clipboard reading (lark-cli doc commands that paste/upload clipboard images) when the osascript «data ...» payload is truncated, was hand-edited, or the clipboard contains a text sample that merely looks like the «data» wrapper.
Common situations: Copying a documentation snippet containing a fake «data HTML...» string; clipboard managers or sanitizers stripping characters; corrupted clipboard sync between devices.
Related errors
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/3d0c6c3791e7bf59.
Report an issue: GitHub.