{"record":{"id":"213466d04d2cc81d","repo":"dotnet/runtime","slug":"event-must-be-an-object-but-got-json-stringify","errorCode":null,"errorMessage":"event must be an object, but got ${JSON.stringify(event)}","messagePattern":"event must be an object, but got (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/debug.ts","lineNumber":132,"sourceCode":"    forceThreadMemoryViewRefresh();\n}\n\nexport function mono_wasm_detach_debugger (): void {\n    forceThreadMemoryViewRefresh();\n    cwraps.mono_wasm_set_is_debugger_attached(false);\n}\n\nexport function mono_wasm_change_debugger_log_level (level: number): void {\n    forceThreadMemoryViewRefresh();\n    cwraps.mono_wasm_change_debugger_log_level(level);\n}\n\n/**\n * Raises an event for the debug proxy\n */\nexport function mono_wasm_raise_debug_event (event: WasmEvent, args = {}): void {\n    if (typeof event !== \"object\")\n        throw new Error(`event must be an object, but got ${JSON.stringify(event)}`);\n\n    if (event.eventName === undefined)\n        throw new Error(`event.eventName is a required parameter, in event: ${JSON.stringify(event)}`);\n\n    if (typeof args !== \"object\")\n        throw new Error(`args must be an object, but got ${JSON.stringify(args)}`);\n\n    // eslint-disable-next-line no-console\n    console.debug(\"mono_wasm_debug_event_raised:aef14bca-5519-4dfe-b35a-f867abc123ae\", JSON.stringify(event), JSON.stringify(args));\n}\n\nexport function mono_wasm_wait_for_debugger (): Promise<void> {\n    return new Promise<void>((resolve) => {\n        const interval = setInterval(() => {\n            if (runtimeHelpers.waitForDebugger != 1) {\n                return;\n            }\n            clearInterval(interval);","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/debug.ts#L114-L150","documentation":"Thrown by `mono_wasm_raise_debug_event` when its first argument is not an object. The function exists to forward structured debugger events to the BrowserDebugProxy via a console.debug magic line, and it requires an object payload to serialise via JSON. Primitives (string/number/boolean/undefined/null) are rejected because the protocol cannot represent them as an event envelope.","triggerScenarios":"Calling `mono_wasm_raise_debug_event(event, args)` (debug.ts:130) with `event` being a string, number, boolean, null, or undefined. Usually a caller passed the event name as a string instead of wrapping it in an object, or passed `undefined` by mistake.","commonSituations":"Custom instrumentation code calling the API with the wrong shape; refactoring that lost the object wrapper; passing a serialized JSON string instead of an object.","solutions":["Pass `event` as an object literal that includes `eventName`, e.g. `mono_wasm_raise_debug_event({ eventName: 'X', ... }, args)`.","If you have a serialized event, `JSON.parse` it before calling.","Add a unit test asserting `typeof event === 'object' && event !== null` at the call site."],"exampleFix":"// before: passed a string\nmono_wasm_raise_debug_event('ScriptCompiled', {}); // throws\n\n// after: pass an object\nmono_wasm_raise_debug_event({ eventName: 'ScriptCompiled' }, {});","handlingStrategy":"type-guard","validationCode":"function raiseDebugEventSafe (event, args) {\n  if (event === null || typeof event !== 'object') {\n    throw new TypeError('event must be a non-null object');\n  }\n  return mono_wasm_raise_debug_event(event, args);\n}","typeGuard":"function isDebugEvent (v: unknown): v is object {\n  return v !== null && typeof v === 'object';\n}","tryCatchPattern":null,"preventionTips":["Build event payloads with a typed factory that returns `object`.","If you hold the event as a serialized string, `JSON.parse` it first.","Add a lint rule or unit test asserting the event argument is an object literal."],"tags":["debugger","validation","typescript","debug-protocol"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}