ComposioHQ/composio · error · Error
Function is required for trigger subscription
Error message
Function is required for trigger subscription
What it means
Plain Error('Function is required for trigger subscription') is thrown by Triggers.subscribe when the fn callback is falsy. subscribe delivers incoming trigger payloads by invoking fn, so a missing handler is rejected immediately. Note this is a generic Error (not ValidationError); the filters object is validated separately afterwards via TriggerSubscribeParamSchema.
Source
Thrown at ts/packages/core/src/models/Triggers.ts:613
/**
* Subscribe to all the triggers
*
* @param fn - The function to call when a trigger is received
* @param filters - The filters to apply to the triggers
*
* @example
* ```ts
*
* triggers.subscribe((data) => {
* console.log(data);
* }, );
* ```
*/
async subscribe(
fn: (_data: IncomingTriggerPayload) => void,
filters: TriggerSubscribeParams = {}
) {
if (!fn) throw new Error('Function is required for trigger subscription');
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
if (!parsedFilters.success) {
throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, {
cause: parsedFilters.error,
});
}
logger.debug('🔄 Subscribing to triggers with filters: ', JSON.stringify(filters, null, 2));
await this.pusherService.subscribe((_data: Record<string, unknown>) => {
logger.debug('Received raw trigger data', JSON.stringify(_data, null, 2));
// Parse using unified method that handles V1/V2/V3 and legacy formats
const parsedData = this.parsePusherPayload(_data);
if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData)) {
try {View on GitHub (pinned to 64b1b85502)
Solutions
- Pass a function as the first argument: triggers.subscribe((data) => {...}, filters)
- Check argument order — fn comes before filters
- If the handler is optional in your code, default it to a no-op logger instead of undefined
Example fix
// before
triggers.subscribe(undefined, { triggerSlugs: ['github_issue_opened'] });
// after
triggers.subscribe(
(data) => console.log('trigger fired', data),
{ triggerSlugs: ['github_issue_opened'] }
); Defensive patterns
Strategy: type-guard
Validate before calling
const handler = onTrigger ?? ((data: unknown) => console.warn('trigger fired, no handler', data));
if (typeof handler !== 'function') throw new Error('subscribe requires a function handler');
triggers.subscribe(handler, filters); Type guard
const isTriggerHandler = (fn: unknown): fn is (data: unknown) => void => typeof fn === 'function';
Try / catch
try {
triggers.subscribe(fn, filters);
} catch (e) {
if (e instanceof Error && /Function is required/.test(e.message)) {
// supply a default handler and retry
}
} Prevention
- Always pass an explicit callback; fn comes before filters
- Default optional handlers to a no-op logger rather than undefined
- Type the call site so a non-function first arg fails at compile time
When it happens
Trigger: Calling triggers.subscribe(undefined, filters), subscribe(null), or otherwise passing a falsy first argument — e.g. wrong argument order putting filters first.
Common situations: Refactors dropping the callback argument; conditional handler construction ending up undefined; passing filters as the first parameter.
Related errors
- Invalid parameters passed to set webhook subscription
- Invalid parameters passed to list triggers
- A non-empty userId is required to create a trigger
- Invalid parameters passed to create trigger
- Trigger type ${slug} not found
AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28).
Data as JSON: /api/errors/cfd75c4410c9aaf7.
Report an issue: GitHub.