{"record":{"id":"18fb2fbf504fd5b2","repo":"appsmithorg/appsmith","slug":"eventname-should-be-a-string","errorCode":null,"errorMessage":"eventName should be a string","messagePattern":"eventName should be a string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/client/src/widgets/CustomWidget/component/customWidgetscript.js","lineNumber":272,"sourceCode":"            }\n          };\n        },\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;","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/appsmithorg/appsmith/blob/8cd9021c24cdbea1c3c12c966073708e83db60c2/app/client/src/widgets/CustomWidget/component/customWidgetscript.js#L254-L290","documentation":"Thrown by window.appsmith.triggerEvent() in a legacy Custom Widget iframe. triggerEvent forwards a named event (with optional context) to the parent Appsmith app so an event handler can be bound on the widget. eventName must be a string because it is used as the event key in the CUSTOM_WIDGET_TRIGGER_EVENT message payload.","triggerScenarios":"Calling appsmith.triggerEvent(undefined), appsmith.triggerEvent(123), appsmith.triggerEvent({name:'click'}), or appsmith.triggerEvent() with no first argument. Passing a Symbol or any non-string identifier.","commonSituations":"Using a variable for the event name that was never assigned; sending a numeric code instead of a named event; destructuring an event object and passing the wrapper instead of the string field.","solutions":["Pass a string literal event name: appsmith.triggerEvent('onItemClick').","Coerce known-safe identifiers: appsmith.triggerEvent(String(eventType)).","Define a const enum/set of allowed event names and reference only those.","Bind the corresponding event handler on the Custom Widget in the Appsmith app so the triggered event has a listener."],"exampleFix":"// before\nappsmith.triggerEvent(event); // event is an object { type: 'click' }\n\n// after\nappsmith.triggerEvent(event.type, event.payload);","handlingStrategy":"validation","validationCode":"if (typeof eventName !== 'string' || eventName.length === 0) {\n  throw new TypeError('triggerEvent eventName must be a non-empty string');\n}\nappsmith.triggerEvent(eventName, context);","typeGuard":"const isEventName = (v) => typeof v === 'string' && v.trim().length > 0;\n\n// usage\nif (isEventName(name)) appsmith.triggerEvent(name, detail);","tryCatchPattern":"try {\n  appsmith.triggerEvent(String(name), detail);\n} catch (e) {\n  console.error('triggerEvent rejected name:', e.message);\n}","preventionTips":["Centralize event names in a const map and reference only those keys.","Bind a matching event handler on the Custom Widget so triggers have listeners.","Coerce with String() only for known-safe identifiers, never user input.","Lint for appsmith.triggerEvent() calls with a non-string first argument."],"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"}