{"record":{"id":"3d0c6c3791e7bf59","repo":"larksuite/cli","slug":"odd-hex-length","errorCode":null,"errorMessage":"odd hex length","messagePattern":"odd hex length","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"shortcuts/doc/clipboard.go","lineNumber":193,"sourceCode":"\tconst prefix = \"\\xc2\\xab\" + \"data \" // « in UTF-8 followed by \"data \"\n\tif !strings.HasPrefix(s, prefix) {\n\t\t// plain string — return as-is\n\t\treturn []byte(s), nil\n\t}\n\t// strip «data XXXX (4-char class code follows immediately, no space) and trailing »\n\ts = s[len(prefix):]\n\tif len(s) >= 4 {\n\t\ts = s[4:] // skip class code, e.g. \"HTML\", \"TIFF\", \"PNGf\"\n\t}\n\ts = strings.TrimSuffix(s, \"\\xc2\\xbb\") // »\n\ts = strings.TrimSpace(s)\n\treturn decodeHex(s)\n}\n\n// decodeHex decodes an uppercase hex string (as produced by osascript) to bytes.\nfunc decodeHex(h string) ([]byte, error) {\n\tif len(h)%2 != 0 {\n\t\treturn nil, fmt.Errorf(\"odd hex length\") //nolint:forbidigo // intermediate decode helper; result discarded by caller on error\n\t}\n\tb := make([]byte, len(h)/2)\n\tfor i := 0; i < len(h); i += 2 {\n\t\thi := hexVal(h[i])\n\t\tlo := hexVal(h[i+1])\n\t\tif hi < 0 || lo < 0 {\n\t\t\treturn nil, fmt.Errorf(\"invalid hex char at %d\", i) //nolint:forbidigo // intermediate decode helper; result discarded by caller on error\n\t\t}\n\t\tb[i/2] = byte(hi<<4 | lo)\n\t}\n\treturn b, nil\n}\n\nfunc hexVal(c byte) int {\n\tswitch {\n\tcase c >= '0' && c <= '9':\n\t\treturn int(c - '0')\n\tcase c >= 'a' && c <= 'f':","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/doc/clipboard.go#L175-L211","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copying a documentation snippet containing a fake «data HTML...» string; clipboard managers or sanitizers stripping characters; corrupted clipboard sync between devices.","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."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Before pasting/uploading, sanity-check the copied content is a real image:\nfile=$(osascript -e 'clipboard info' | grep -o '«class PNGf»' ) || echo 'clipboard does not hold image data'","typeGuard":"func looksLikeHexPairPayload(s string) bool { return len(s)%2 == 0 && len(s) > 0 }","tryCatchPattern":"// The command already falls back internally; at the shell level, retry after recopying:\nif ! lark-cli doc import --clipboard; then\n  echo \"clipboard payload not an image; recopy the image and retry\" >&2\nfi","preventionTips":["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."],"tags":["macos","clipboard","hex-decode","osascript"],"backgroundTag":"invalid-hex-payload","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}