larksuite/cli · warning
invalid hex char at %d
Error message
invalid hex char at %d
What it means
decodeHex validates each character of the osascript «data ...» hex payload; when a character at position i is outside 0-9/a-f/A-F it reports the exact offset. Like the odd-length case, this is an intermediate parse error for clipboard image data; callers treat it as 'not an image' and continue.
Source
Thrown at shortcuts/doc/clipboard.go:200
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':
return int(c-'a') + 10
case c >= 'A' && c <= 'F':
return int(c-'A') + 10
}
return -1
}
View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Copy an actual image (screenshot or copy-image in the source app) instead of copying text that contains the data wrapper.
- Inspect the clipboard contents in a text editor and clear it (pbcopy < /dev/null) before retrying.
- If you need to embed image data, use the proper file/upload flags of the command rather than the clipboard.
Defensive patterns
Strategy: fallback
Validate before calling
# Verify clipboard holds image data before running the command: osascript -e 'clipboard info' | grep -q '«class PNGf»\|«class TIFF»' && echo ok || echo 'clipboard has no image data'
Type guard
func isHexPayload(s string) bool {
for i := 0; i < len(s); i++ {
c := s[i]
if !(c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') {
return false
}
}
return len(s)%2 == 0
} Try / catch
if ! lark-cli doc import --clipboard; then echo "clipboard content is text, not an image; copy the image itself and retry" >&2 fi
Prevention
- Copy the image itself (screenshot/copy-image) rather than copying text that embeds base64 or data URIs.
- Check 'clipboard info' in Script Editor to confirm a binary image class is present before automation.
- Keep the clipboard app-free of transformers that alter binary payloads.
When it happens
Trigger: The macOS clipboard holds an «data XXXX...» literal whose payload includes non-hex characters — typically because the clipboard actually contains text (a doc snippet or base64 string) rather than binary image data captured by osascript.
Common situations: Copying a data-URI example (base64 contains characters like '+', '/', '=') from docs and running a command that expects a clipboard image; clipboard apps transforming the payload.
Related errors
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/e13839fe4502382a.
Report an issue: GitHub.