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

  1. Pass a function as the first argument: triggers.subscribe((data) => {...}, filters)
  2. Check argument order — fn comes before filters
  3. 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

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


AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28). Data as JSON: /api/errors/cfd75c4410c9aaf7. Report an issue: GitHub.