{"record":{"id":"d40702c4bba2c15f","repo":"appsmithorg/appsmith","slug":"contextobj-should-be-an-object-d40702","errorCode":null,"errorMessage":"contextObj should be an object","messagePattern":"contextObj should be an object","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js","lineNumber":254,"sourceCode":"        },\n        updateModel: (obj) => {\n          if (!obj || typeof obj !== \"object\") {\n            throw new Error(\"updateModel expects an object as parameter\");\n          }\n\n          appsmith.model = Object.assign(\n            Object.assign({}, appsmith.model),\n            obj,\n          );\n\n          // Send an update model message to the parent\n          channel.postMessage(EVENTS.CUSTOM_WIDGET_UPDATE_MODEL, obj);\n        },\n        triggerEvent: (eventName, contextObj) => {\n          if (typeof eventName !== \"string\") {\n            throw new Error(\"eventName should be a string\");\n          } else if (contextObj && typeof contextObj !== \"object\") {\n            throw new Error(\"contextObj should be an object\");\n          }\n\n          // Send a trigger event message to the parent\n          channel.postMessage(EVENTS.CUSTOM_WIDGET_TRIGGER_EVENT, {\n            eventName,\n            contextObj,\n          });\n        },\n        model: {},\n        onReady: (fn) => {\n          if (typeof fn !== \"function\") {\n            throw new Error(\"onReady expects a function as parameter\");\n          }\n\n          onReady = fn;\n\n          if (isReady && !isReadyCalled && onReady) {\n            onReady();","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js#L236-L272","documentation":"Thrown by the else-if branch of window.appsmith.triggerEvent() in the WDS Custom Widget iframe. After the string eventName check passes, an optional contextObj is validated: if it is truthy but not an object, the call is rejected because it is serialized into the CUSTOM_WIDGET_TRIGGER_EVENT payload. null and undefined are allowed (skipped by the truthy check).","triggerScenarios":"Calling appsmith.triggerEvent('select', 'row-1'), appsmith.triggerEvent('select', 7), or appsmith.triggerEvent('select', Symbol()) in the WDS widget.","commonSituations":"Passing a primitive value directly instead of an event-detail object; forwarding a DOM target value rather than a wrapped detail.","solutions":["Wrap context in an object: appsmith.triggerEvent('select', { id: rowId }).","Omit the argument entirely when there is no context: appsmith.triggerEvent('ready').","Pass null explicitly to signal no context: appsmith.triggerEvent('blur', null)."],"exampleFix":"// before\nappsmith.triggerEvent('select', selectedId); // primitive number/string\n\n// after\nappsmith.triggerEvent('select', { id: selectedId });","handlingStrategy":"validation","validationCode":"const ctx = contextObj == null ? undefined : contextObj;\nif (ctx !== undefined && (typeof ctx !== 'object' || ctx === null)) {\n  throw new TypeError('triggerEvent contextObj must be an object');\n}\nappsmith.triggerEvent(eventName, ctx);","typeGuard":"const isContextObject = (v) =>\n  v == null || (typeof v === 'object' && !Array.isArray(v));\n\n// usage\nif (isContextObject(detail)) appsmith.triggerEvent(name, detail);","tryCatchPattern":"try {\n  appsmith.triggerEvent(name, detail ? { value: detail } : undefined);\n} catch (e) {\n  console.error('triggerEvent rejected context:', e.message);\n}","preventionTips":["Wrap any primitive context under an object key.","Omit the second argument when there is no context.","Pass null to explicitly signal 'no context'.","Serialize only plain data; avoid DOM nodes or class instances as context."],"tags":["custom-widget","wds","appsmith-api","parameter-validation","javascript"],"backgroundTag":null,"analyzedSha":"8cd9021c24cdbea1c3c12c966073708e83db60c2","analyzedAt":"2026-08-12T22:14:19.293Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}