{"record":{"id":"e13839fe4502382a","repo":"larksuite/cli","slug":"invalid-hex-char-at-d","errorCode":null,"errorMessage":"invalid hex char at %d","messagePattern":"invalid hex char at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"shortcuts/doc/clipboard.go","lineNumber":200,"sourceCode":"\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':\n\t\treturn int(c-'a') + 10\n\tcase c >= 'A' && c <= 'F':\n\t\treturn int(c-'A') + 10\n\t}\n\treturn -1\n}\n","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/doc/clipboard.go#L182-L218","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"# Verify clipboard holds image data before running the command:\nosascript -e 'clipboard info' | grep -q '«class PNGf»\\|«class TIFF»' && echo ok || echo 'clipboard has no image data'","typeGuard":"func isHexPayload(s string) bool {\n    for i := 0; i < len(s); i++ {\n        c := s[i]\n        if !(c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') {\n            return false\n        }\n    }\n    return len(s)%2 == 0\n}","tryCatchPattern":"if ! lark-cli doc import --clipboard; then\n  echo \"clipboard content is text, not an image; copy the image itself and retry\" >&2\nfi","preventionTips":["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."],"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"}