{"record":{"id":"62a2410f8e943cee","repo":"dotnet/runtime","slug":"args-must-be-an-object-but-got-json-stringify-a","errorCode":null,"errorMessage":"args must be an object, but got ${JSON.stringify(args)}","messagePattern":"args must be an object, but got (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/debug.ts","lineNumber":138,"sourceCode":"}\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);\n            resolve();\n        }, 100);\n    });\n}\n\nexport function mono_wasm_debugger_attached (): void {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/debug.ts#L120-L156","documentation":"Thrown by `mono_wasm_raise_debug_event` when the optional `args` argument is present but not an object. The default `{}` is fine; passing a primitive (e.g. an array or string) violates the contract that args is a key/value bag serialised as JSON alongside the event.","triggerScenarios":"Calling `mono_wasm_raise_debug_event(event, args)` (debug.ts:137) where `args` is a string, number, array, null, or boolean. Most commonly the caller passes a positional array of values, or passes `null` thinking it means 'no args'.","commonSituations":"Refactoring that changed args from object to array; passing the result of a function that returns null on empty; misunderstanding that `null` is not an object (typeof null === 'object' is true, but here null still triggers because the runtime asserts the value before that quirk only when args !== undefined — note the check is `typeof args !== 'object'`, which lets null through, so the realistic trigger is arrays/strings/numbers/booleans).","solutions":["Omit `args` (or pass `{}`) when there are no extra parameters.","If you have positional data, wrap it: `{ params: [...] }`.","Ensure helper builders return `{}` rather than `null` for the no-args case."],"exampleFix":"// before: array passed as args\nmono_wasm_raise_debug_event(ev, ['a', 'b']); // throws\n\n// after: wrap positional data in an object\nmono_wasm_raise_debug_event(ev, { params: ['a', 'b'] });","handlingStrategy":"type-guard","validationCode":"function raiseDebugEventSafe (event, args) {\n  const safeArgs = args === undefined ? {} : args;\n  if (safeArgs === null || typeof safeArgs !== 'object') {\n    throw new TypeError('args must be an object');\n  }\n  return mono_wasm_raise_debug_event(event, safeArgs);\n}","typeGuard":"function isArgsBag (v: unknown): v is Record<string, unknown> {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Default `args` to `{}` at the call site; never pass `null`.","Wrap positional payloads in an object: `{ params: [...] }`.","Type the parameter as `Record<string, unknown>` to forbid arrays."],"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"}