{"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/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/debug.ts#L114-L150","documentation":"Thrown by mono_wasm_raise_debug_event() in debug.ts when the `event` argument is not of type 'object'. This function raises a debug event (e.g. breakpoint/script loaded) to the BrowserDebugProxy which listens on console.debug with a fixed magic GUID. Passing a primitive (string, number, boolean, symbol, bigint, undefined) instead of an event object is a programming contract violation. Note: typeof null === 'object', so null passes this check but will throw a TypeError on the next line accessing event.eventName.","triggerScenarios":"Calling mono_wasm_raise_debug_event with a string/number/undefined instead of an object, e.g. mono_wasm_raise_debug_event('breakpoint') or mono_wasm_raise_debug_event(someId). Internal callers that build the event lazily and pass a primitive placeholder.","commonSituations":"Hand-written instrumentation or a fork that calls mono_wasm_raise_debug_event with a non-object. A refactor that changed what is passed in but did not wrap it in { eventName, ... }.","solutions":["Pass an object literal: { eventName: '...', ...payload }.","Ensure the variable you pass is not undefined (a missing import/typo yields undefined).","If you intended no event, do not call the function rather than passing a primitive."],"exampleFix":"// before\nmono_wasm_raise_debug_event('breakpointHit');\n\n// after\nmono_wasm_raise_debug_event({ eventName: 'breakpointHit', id: bpId });","handlingStrategy":"type-guard","validationCode":"function raiseDebugEventSafe(event: unknown, args?: unknown) {\n  if (event === null || typeof event !== \"object\") {\n    throw new TypeError('event must be a non-null object');\n  }\n  // ...then call mono_wasm_raise_debug_event(event as WasmEvent, args as any);\n}","typeGuard":"function isWasmEvent(event: unknown): event is { eventName: string } {\n  return event !== null && typeof event === \"object\"\n    && typeof (event as any).eventName === \"string\";\n}","tryCatchPattern":"null","preventionTips":["Always construct events as object literals with eventName.","Type the parameter as WasmEvent so the compiler enforces it.","Guard against null explicitly (typeof null === 'object')."],"tags":["debugger","type-error","events","contracts"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}