Skip to content

Instantly share code, notes, and snippets.

@endel
Last active December 18, 2025 18:35
Show Gist options
  • Select an option

  • Save endel/4eca11c09ba0335c0867d47f67694773 to your computer and use it in GitHub Desktop.

Select an option

Save endel/4eca11c09ba0335c0867d47f67694773 to your computer and use it in GitHub Desktop.
Debugging "refId not found" errors in @colyseus/schema v3
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);
}
// ...
}
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