appsmithorg/appsmith · error · Error
eventName should be a string
Error message
eventName should be a string
What it means
Thrown by window.appsmith.triggerEvent() in the WDS Custom Widget iframe. eventName must be a string because it becomes the event key in the CUSTOM_WIDGET_TRIGGER_EVENT payload sent to the parent app. The WDS variant uses the same triggerEvent contract as the legacy widget.
Source
Thrown at app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js:252
}
};
},
updateModel: (obj) => {
if (!obj || typeof obj !== "object") {
throw new Error("updateModel expects an object as parameter");
}
appsmith.model = Object.assign(
Object.assign({}, appsmith.model),
obj,
);
// Send an update model message to the parent
channel.postMessage(EVENTS.CUSTOM_WIDGET_UPDATE_MODEL, obj);
},
triggerEvent: (eventName, contextObj) => {
if (typeof eventName !== "string") {
throw new Error("eventName should be a string");
} else if (contextObj && typeof contextObj !== "object") {
throw new Error("contextObj should be an object");
}
// Send a trigger event message to the parent
channel.postMessage(EVENTS.CUSTOM_WIDGET_TRIGGER_EVENT, {
eventName,
contextObj,
});
},
model: {},
onReady: (fn) => {
if (typeof fn !== "function") {
throw new Error("onReady expects a function as parameter");
}
onReady = fn;
View on GitHub (pinned to 8cd9021c24)
Solutions
- Pass a string literal event name: appsmith.triggerEvent('onRowSelect').
- Coerce known-safe identifiers: appsmith.triggerEvent(String(e.type)).
- Centralize event names in a const map and reference only those.
- Ensure a matching event handler is bound on the WDS Custom Widget in the Appsmith app.
Example fix
// before appsmith.triggerEvent(event); // event is an object // after appsmith.triggerEvent(event.name, event.detail);
Defensive patterns
Strategy: validation
Validate before calling
if (typeof eventName !== 'string' || eventName.length === 0) {
throw new TypeError('triggerEvent eventName must be a non-empty string');
}
appsmith.triggerEvent(eventName, detail); Type guard
const isEventName = (v) => typeof v === 'string' && v.trim().length > 0; // usage if (isEventName(name)) appsmith.triggerEvent(name, detail);
Try / catch
try {
appsmith.triggerEvent(String(name), detail);
} catch (e) {
console.error('triggerEvent rejected name:', e.message);
} Prevention
- Centralize event names in a const map; reference only those keys.
- Bind a matching event handler on the WDS Custom Widget.
- Coerce only known-safe identifiers with String(); never raw user input.
- Ensure the shared event-name module is actually imported in the iframe script.
When it happens
Trigger: Calling appsmith.triggerEvent(undefined), appsmith.triggerEvent(123), appsmith.triggerEvent({type:'select'}), or appsmith.triggerEvent() with no first argument in the WDS widget.
Common situations: Forwarding a numeric event code; passing an event object instead of its string type field; referencing an event-name constant that was not exported from the shared module.
Related errors
- onThemeChange expects a function as parameter
- onModelChange expects a function as parameter
- updateModel expects an object as parameter
- contextObj should be an object
- onReady expects a function as parameter
AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12).
Data as JSON: /api/errors/81f55c9d1b71b5f1.
Report an issue: GitHub.