{"record":{"id":"0a90f10bd5225a48","repo":"microsoft/typescript-go","slug":"this-msgpayload-tostring-utf-8","errorCode":null,"errorMessage":"this._msgPayload.toString(\"utf-8\")","messagePattern":"this\\._msgPayload\\.toString\\(\"utf-8\"\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"_packages/native-preview/src/api/syncChannel.ts","lineNumber":313,"sourceCode":"        for (;;) {\r\n            this.readTuple();\r\n\r\n            switch (this._msgType) {\r\n                case MSG_RESPONSE: {\r\n                    // Compare raw bytes instead of decoding to string.\r\n                    if (!methodBuf.equals(this._msgName)) {\r\n                        throw new Error(\r\n                            `name mismatch for response: expected \\`${method}\\`, got \\`${this._msgName.toString(\"utf-8\")}\\``,\r\n                        );\r\n                    }\r\n                    if (this.collectTiming) {\r\n                        this.lastBytesReceived = this._msgPayload.length;\r\n                    }\r\n                    return this._msgPayload;\r\n                }\r\n                case MSG_ERROR: {\r\n                    if (methodBuf.equals(this._msgName)) {\r\n                        throw new Error(this._msgPayload.toString(\"utf-8\"));\r\n                    }\r\n                    throw new Error(\r\n                        `name mismatch for response: expected \\`${method}\\`, got \\`${this._msgName.toString(\"utf-8\")}\\``,\r\n                    );\r\n                }\r\n                case MSG_CALL: {\r\n                    this.handleCall(this._msgName.toString(\"utf-8\"), this._msgPayload);\r\n                    break;\r\n                }\r\n                default:\r\n                    throw new Error(`Invalid message type from child: ${this._msgType}`);\r\n            }\r\n        }\r\n    }\r\n\r\n    // ── Callback handling ───────────────────────────────────────────\r\n\r\n    /**\r","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/_packages/native-preview/src/api/syncChannel.ts#L295-L331","documentation":"This is the channel's server-error propagation: when the child answers a request with an MSG_ERROR frame whose name matches the request, the payload (the server's error message, e.g. 'unknown method', assertion failures, invalid arguments) is re-thrown on the client as a plain Error. It is the normal path by which every server-side failure surfaces in sync-client code — the message text itself comes from tsgo, not this file.","triggerScenarios":"Any server-side exception during an API request: passing invalid snapshot/project/object ids (e.g. after state was released), malformed request payloads, unimplemented methods, or internal tsgo assertion failures. The matching error 77/79 name checks do not fire here — this is the well-matched error case.","commonSituations":"Calling APIs with stale object ids from previous snapshots; requesting methods unavailable in the running binary version; hitting genuine tsgo bugs.","solutions":["Read the propagated message — it identifies the actual server-side failure and usually the fix","Ensure object ids passed (snapshot ids, project ids, object handles) come from the current session's responses","Wrap API calls in try/catch and surface the message; recreate the client if state-dependent ids are implicated"],"exampleFix":"// before\nconst r = client.apiRequest(\"someMethod\", { snapshot: oldId });\n\n// after\ntry {\n  const r = client.apiRequest(\"someMethod\", { snapshot: currentId });\n} catch (e) {\n  console.error(\"tsgo server error:\", (e as Error).message);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { data = client.apiRequest(\"method\", args); } catch (e) {\n  const msg = (e as Error).message;\n  if (msg.includes(\"unknown\") || msg.includes(\"invalid\")) { /* fix arguments/ids per message */ }\n  else if (msg.includes(\"name mismatch\")) { /* desync: recreate client */ }\n  else throw e;\n}","preventionTips":["Always wrap sync API requests and log the propagated server message verbatim","Use object ids only from the current session's responses","Check the message for method/argument hints before assuming a client bug"],"tags":["typescript","rpc","server-error","propagation"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}