{"record":{"id":"ebb31d67559ead80","repo":"DIYgod/RSSHub","slug":"h64-is-not-supported-in-worker-shim-use-h64tostri","errorCode":null,"errorMessage":"h64 is not supported in Worker shim, use h64ToString instead","messagePattern":"h64 is not supported in Worker shim, use h64ToString instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/xxhash-wasm.ts","lineNumber":59,"sourceCode":"                    chunks.push(typeof input === 'string' ? encoder.encode(input) : input);\n                    return this;\n                },\n                digest() {\n                    const totalLength = chunks.reduce((sum, arr) => sum + arr.length, 0);\n                    const combined = new Uint8Array(totalLength);\n                    let offset = 0;\n                    for (const chunk of chunks) {\n                        combined.set(chunk, offset);\n                        offset += chunk.length;\n                    }\n                    return simpleHash32(combined, seed);\n                },\n            };\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    };","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/xxhash-wasm.ts#L41-L77","documentation":"The xxhash-wasm Workers shim (lib/shims/xxhash-wasm.ts) implements h64ToString with a synchronous JS fallback but cannot implement h64 (returning bigint) — the original used async SHA-256-backed hashing that cannot be made synchronous in Workers. h64 throws by design to redirect callers to h64ToString, which is the only variant actually used in the codebase (cache.ts, status.ts, several routes).","triggerScenarios":"Calling (await xxhash()).h64(input) — the bigint-returning variant — under Workers. h64ToString, h32 and h32ToString all work; only h64/h64Raw/create64 throw.","commonSituations":"A new route copied from xxhash-wasm docs that uses h64 directly; logic that needs a numeric bigint hash key; migrating Node code that called h64.","solutions":["Use h64ToString instead — it returns the same hash as a hex string and is the codebase standard.","If a bigint is truly required, run that code path on the Node runtime where the real wasm h64 is available.","Where h64ToString is used as a guid/key, ensure uniqueness the same way existing routes do (concat with link/id)."],"exampleFix":"// before\nconst { h64 } = await xxhash();\nconst key = h64(input); // throws under Workers\n// after\nconst { h64ToString } = await xxhash();\nconst key = h64ToString(input); // works under Workers","handlingStrategy":"fallback","validationCode":"// choose the Workers-safe variant up front\nimport xxhash from '@/shims/xxhash-wasm';\nfunction pickHashMethod(needsBigInt: boolean) {\n  const isWorkers = typeof process === 'undefined';\n  if (needsBigInt && isWorkers) {\n    throw new Error('h64 (bigint) is unavailable under Workers — use h64ToString');\n  }\n  return needsBigInt ? 'h64' : 'h64ToString';\n}","typeGuard":"function isH64ShimError(e: unknown): e is Error {\n  return e instanceof Error && /h64 is not supported in Worker shim/.test(e.message);\n}","tryCatchPattern":"const api = await xxhash();\nlet key: string;\ntry {\n  key = api.h64ToString(input); // preferred, Workers-safe\n} catch (e) {\n  if (isH64ShimError(e)) key = api.h64ToString(input); // never reached for h64ToString itself\n  throw e;\n}\n// if you must call h64():\n//   try { const n = api.h64(input); }\n//   catch (e) { if (isH64ShimError(e)) key = api.h64ToString(input); else throw e; }","preventionTips":["Always use h64ToString — it is the codebase standard and works under Workers.","Do not copy h64 examples from xxhash-wasm docs into Worker-deployed routes.","Reserve bigint h64 for Node-runtime-only code paths."],"tags":["cloudflare-workers","xxhash","shim","caching","hashing"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}