{"record":{"id":"7bc75ac5858a76c5","repo":"appsmithorg/appsmith","slug":"contextobj-should-be-an-object","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/CustomWidget/component/customWidgetscript.js","lineNumber":274,"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        ui: {},\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) {","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/src/widgets/CustomWidget/component/customWidgetscript.js#L256-L292","documentation":"Thrown by the else-if branch of window.appsmith.triggerEvent() in a legacy Custom Widget iframe. After eventName passes its string check, the optional contextObj is validated: if it is truthy but not an object, the call is rejected because contextObj is serialized into the CUSTOM_WIDGET_TRIGGER_EVENT payload sent to the parent.","triggerScenarios":"Calling appsmith.triggerEvent('click', 'clicked'), appsmith.triggerEvent('click', 42), or appsmith.triggerEvent('click', Symbol()). null/undefined are allowed (the truthy check skips them); only truthy primitives are rejected.","commonSituations":"Passing a single value instead of wrapping it in an object; forwarding a DOM event's target string instead of an event-detail object; passing a form value directly as context.","solutions":["Wrap context data in an object: appsmith.triggerEvent('click', { value: someValue }).","Pass null or undefined explicitly when there is no context: appsmith.triggerEvent('ready').","If forwarding a DOM event, extract a plain serializable subset: appsmith.triggerEvent('change', { value: e.target.value })."],"exampleFix":"// before\nappsmith.triggerEvent('search', searchText); // string, not object\n\n// after\nappsmith.triggerEvent('search', { query: searchText });","handlingStrategy":"validation","validationCode":"// contextObj is optional; only validate when provided\nconst 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 before sending.","Omit the second argument entirely when there is no context.","Pass null explicitly to signal 'no context' rather than a primitive.","Serialize only plain data; avoid passing DOM nodes or class instances as context."],"tags":["custom-widget","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"}