{"record":{"id":"ac1a65a19bdeb484","repo":"chenhg5/cc-connect","slug":"wecom-ws-decode-aeskey-hex-w","errorCode":null,"errorMessage":"wecom-ws: decode aeskey hex: %w","messagePattern":"wecom-ws: decode aeskey hex: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/websocket_media.go","lineNumber":224,"sourceCode":"\tif s == \"\" {\n\t\treturn nil, fmt.Errorf(\"wecom-ws: empty aeskey\")\n\t}\n\tvar b strings.Builder\n\tb.Grow(len(s))\n\tfor i := 0; i < len(s); i++ {\n\t\tswitch s[i] {\n\t\tcase '\\n', '\\r', ' ', '\\t':\n\t\t\tcontinue\n\t\tdefault:\n\t\t\tb.WriteByte(s[i])\n\t\t}\n\t}\n\ts = b.String()\n\n\tif len(s) == 64 && isHexString(s) {\n\t\tkey, err := hex.DecodeString(s)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"wecom-ws: decode aeskey hex: %w\", err)\n\t\t}\n\t\tif len(key) != 32 {\n\t\t\treturn nil, fmt.Errorf(\"wecom-ws: aeskey hex length %d, want 32 bytes\", len(key))\n\t\t}\n\t\treturn key, nil\n\t}\n\n\t// URL-safe alphabet → standard (RFC 4648 §5)\n\ts = strings.ReplaceAll(s, \"-\", \"+\")\n\ts = strings.ReplaceAll(s, \"_\", \"/\")\n\n\tswitch len(s) % 4 {\n\tcase 0:\n\tcase 2:\n\t\ts += \"==\"\n\tcase 3:\n\t\ts += \"=\"\n\tdefault:","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/websocket_media.go#L206-L242","documentation":"Wrap of hex.DecodeString inside decodeWeComAESKey's normalization ladder: the input looked like a 64-char hex string (passed the isHexString check) but Go's decoder still rejected it. In practice near-impossible since isHexString pre-validates the alphabet; firing indicates an edge case in the heuristic or corrupted input, after whitespace was already stripped.","triggerScenarios":"Thrown at platform/wecom/websocket_media.go:224 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log the normalized input length and first bytes to see why isHexString and hex.DecodeString disagree","If it fires in production, fall through to the Base64 branch instead of hard-failing, since the hex path is only a compatibility guess","Add a unit test covering the divergent input to pin the behavior"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}