{"record":{"id":"c0e2cd6e800ddf64","repo":"discordjs/discord.js","slug":"shard-payload-shardid-does-not-exist","errorCode":null,"errorMessage":"Shard ${payload.shardId} does not exist","messagePattern":"Shard (.+?) does not exist","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/ws/src/utils/WorkerBootstrapper.ts","lineNumber":109,"sourceCode":"\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Destroy: {\n\t\t\t\t\t\tawait this.destroy(payload.shardId, payload.options);\n\t\t\t\t\t\tconst response: WorkerReceivePayload = {\n\t\t\t\t\t\t\top: WorkerReceivePayloadOp.Destroyed,\n\t\t\t\t\t\t\tshardId: payload.shardId,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tparentPort!.postMessage(response);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.Send: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new RangeError(`Shard ${payload.shardId} does not exist`);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait shard.send(payload.payload);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.SessionInfoResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.ShardIdentifyResponse: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase WorkerSendPayloadOp.FetchStatus: {\n\t\t\t\t\t\tconst shard = this.shards.get(payload.shardId);\n\t\t\t\t\t\tif (!shard) {\n\t\t\t\t\t\t\tthrow new Error(`Shard ${payload.shardId} does not exist`);","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/ws/src/utils/WorkerBootstrapper.ts#L91-L127","documentation":"In setupThreadEvents, when the parent thread sends a Send payload, the bootstrapper resolves the target shard from its shards Map. If the shard id is unknown it throws a RangeError because the payload cannot be forwarded.","triggerScenarios":"The parent process sends a WorkerSendPayloadOp.Send message with payload.shardId not present in the worker's shards Map — e.g. a send was queued before/after the shard was spawned or destroyed.","commonSituations":"Calling manager.send() or shard.send() through the manager while a shard has been destroyed; shard count reduced at runtime; messages racing shard respawn during resharding.","solutions":["Ensure the shard is connected before sending payloads through it","Check this.shards.has(shardId) before issuing Send payloads from the parent","Guard against concurrent destroy + send operations (await destroy completion before sending)","Verify shardIds configuration so the parent only routes to ids owned by this worker"],"exampleFix":"// before\nawait manager.send(7, payload);\n// after\nconst shardIds = await manager.getShardIds();\nif (shardIds.includes(7)) {\n  await manager.send(7, payload);\n}","handlingStrategy":"try-catch","validationCode":"if (!bootstrapper.shards.has(payload.shardId)) {\n  // drop or requeue the payload instead of forwarding\n  return;\n}","typeGuard":"function shardExists(bootstrapper: WorkerBootstrapper, shardId: number): boolean {\n  return bootstrapper.shards.has(shardId);\n}","tryCatchPattern":"try {\n  await bootstrapper.send(shardId, payload);\n} catch (e) {\n  if (e instanceof RangeError && e.message.includes('does not exist')) {\n    queue.push(payload); // requeue until shard respawns\n  } else throw e;\n}","preventionTips":["Await shard spawn before issuing sends","Route sends only to ids listed in getShardIds()"],"tags":["websocket","sharding","range-error"],"backgroundTag":"shard-not-found","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}