{"record":{"id":"0ac6ac1076612010","repo":"DIYgod/RSSHub","slug":"h64raw-is-not-supported-in-worker-shim","errorCode":null,"errorMessage":"h64Raw is not supported in Worker shim","messagePattern":"h64Raw is not supported in Worker shim","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shims/xxhash-wasm.ts","lineNumber":72,"sourceCode":"            };\n        },\n        // h64 methods use async SHA-256 but return sync - this is a limitation\n        // In practice, only h64ToString is used and it's called with await xxhash()\n        h64: (_input: string, _seed?: bigint): bigint => {\n            throw new Error('h64 is not supported in Worker shim, use h64ToString instead');\n        },\n        h64ToString: (input: string, _seed?: bigint): string => {\n            // This needs to be sync to match the API, but we use a simple hash\n            // The actual usage in cache.ts awaits xxhash() first, so this works\n            let hash = 0n;\n            const data = encoder.encode(input);\n            for (const byte of data) {\n                hash = ((hash << 5n) - hash + BigInt(byte)) & 0xff_ff_ff_ff_ff_ff_ff_ffn;\n            }\n            return hash.toString(16).padStart(16, '0');\n        },\n        h64Raw: (_inputBuffer: Uint8Array, _seed?: bigint): bigint => {\n            throw new Error('h64Raw is not supported in Worker shim');\n        },\n        create64: (_seed?: bigint): XXHash<bigint> => {\n            throw new Error('create64 is not supported in Worker shim');\n        },\n    };\n}\n\nexport default xxhash;\n","sourceCodeStart":54,"sourceCodeEnd":81,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/xxhash-wasm.ts#L54-L81","documentation":"Thrown by the Cloudflare Workers shim for xxhash-wasm when h64Raw is invoked. The real xxhash-wasm uses WebAssembly to compute 64-bit hashes, which Workers cannot load here, so the shim only implements h64ToString with a sync BigInt fallback and deliberately throws for the raw-buffer 64-bit API. It exists to fail loudly rather than silently return a wrong value.","triggerScenarios":"Calling xxhash().h64Raw(uint8Array, seed) anywhere in code that runs in the Worker bundle (e.g. lib/utils/cache.ts or any cache key path that resolves to the raw 64-bit API). Also triggered if library code branches on the existence of h64Raw rather than using h64ToString.","commonSituations":"Porting an existing RSSHub feature that uses xxhash-wasm's h64Raw directly into the Cloudflare Worker build; upgrading a dependency that newly calls h64Raw; running the Worker bundle locally with `wrangler dev` instead of the Node entry.","solutions":["Switch the call site to h64ToString(input) which the shim implements (lib/shims/xxhash-wasm.ts:61).","Gate the raw-hash code path so it only runs in the Node build, not the Worker bundle (e.g. dynamic import guarded by environment).","If raw bytes are required, hash a string conversion of the buffer with h64ToString instead of using h64Raw.","Run the route under Node/RSSHub core rather than the Worker shim if 64-bit raw hashing is mandatory."],"exampleFix":"// before\nconst hash = (await xxhash()).h64Raw(buffer, seed);\n// after\nconst hash = (await xxhash()).h64ToString(Buffer.from(buffer).toString('utf8'), seed);","handlingStrategy":"type-guard","validationCode":"function supportsH64Raw(h: any): boolean {\n  try { return typeof h.h64Raw === 'function' && /\\[native code\\]|simpleHash/.test(h.h64Raw.toString()) === false; } catch { return false; }\n}\n// Safer: feature-detect by source\nconst api = await xxhash();\nif (!('h64Raw' in api) || /Worker shim/.test(String(api.h64Raw))) { /* use h64ToString */ }","typeGuard":"const isH64RawAvailable = (api: XXHashAPI): boolean => {\n  try { api.h64Raw(new Uint8Array(0)); return true; } catch { return false; }\n};","tryCatchPattern":"try {\n  return (await xxhash()).h64Raw(buf, seed);\n} catch (e) {\n  if (/not supported in Worker shim/.test(String((e as Error).message))) {\n    return (await xxhash()).h64ToString(Buffer.from(buf).toString(), seed);\n  }\n  throw e;\n}","preventionTips":["Always prefer h64ToString over h64Raw for cache keys - it is the only 64-bit method the Worker shim implements.","When writing shared utilities, branch on environment (Node vs Worker) before picking a hash method.","Add a smoke test that exercises the hashing path in the Worker bundle."],"tags":["cloudflare-workers","xxhash","shim","wasm","hashing"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}