Last active
December 18, 2025 18:35
-
-
Save endel/4eca11c09ba0335c0867d47f67694773 to your computer and use it in GitHub Desktop.
Debugging "refId not found" errors in @colyseus/schema v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fs from "fs"; | |
| import { Schema, Reflection } from "@colyseus/schema"; | |
| // ... | |
| class MyRoom extends Room { | |
| // ... | |
| onCreate() { | |
| fs.writeFileSync("patch-debug.log", ""); | |
| setInterval(() => { | |
| fs.appendFileSync("patch-debug.log", `\n\nPATCH => ${Schema.debugRefIds(state)}\n`); | |
| fs.appendFileSync("patch-debug.log", `ENCODE ORDER => ${Schema.debugRefIdEncodingOrder(this.state, "allChanges")}\n`); | |
| const serializer = (this['_serializer'] as any); | |
| const encodeAll = serializer['encoder'].encodeAll(); | |
| const decoder = Reflection.decode(serializer.handshake()); | |
| try { | |
| decoder.decode(encodeAll); | |
| } catch (e) { | |
| console.error(e); | |
| process.exit(1); | |
| } | |
| }, 2000); | |
| } | |
| // ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| src/decoder/Decoder.ts | |
| if (!nextRef) { | |
| + throw new Error(`"refId" not found: ${nextRefId}`); | |
| - // throw new Error(`"refId" not found: ${nextRefId}`); | |
| console.error(`"refId" not found: ${nextRefId}`, { previousRef: ref, previousRefId: this.currentRefId }); | |
| console.warn("Please report this issue to the developers."); | |
| this.skipCurrentStructure(bytes, it, totalBytes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment