Kong/insomnia · error

Could not get folder by index

Error message

Could not get folder by index ${folderIndex}. Must be between 0-${ancestors.length - 1}

What it means

Template-tag runtime error for {% request 'folder' N %}: the requested folder index is outside the request's ancestor chain (0 to ancestors.length-1). The invalid index and valid range are interpolated.

Solutions

  1. Lower the folder index to a value within 0..ancestors.length-1
  2. Check how deeply nested the request actually is
  3. Use the workspace/root attributes instead if the request is at the top level
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/insomnia/src/common/templating/local-template-tags.ts:995 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26). Data as JSON: /api/errors/c2f8d992a390135a. Report an issue: GitHub.

Appendix: source

Thrown at packages/insomnia/src/common/templating/local-template-tags.ts:995

          }
          if (attribute === 'oauth2') {
            return access.accessToken;
          }
          if (attribute === 'oauth2-identity') {
            return access.identityToken;
          }
          if (attribute === 'oauth2-refresh') {
            return access.refreshToken;
          }
        }
        if (attribute === 'name') {
          return request.name;
        }
        if (attribute === 'folder') {
          const ancestors = await context.util.models.request.getAncestors(request);
          const doc = ancestors[folderIndex || 0];
          if (!doc) {
            throw new Error(`Could not get folder by index ${folderIndex}. Must be between 0-${ancestors.length - 1}`);
          }
          return doc ? doc.name : null;
        }

        return null;
      },
    },
  },
];

export const localTemplateTags: TemplateTag[] = localTemplatePlugins.map(t => ({
  plugin: {
    name: t.templateTag.name,
    description: 'Built-in plugin',
    version: '0.0.0',
    directory: '',
    config: {
      disabled: false,

View on GitHub (pinned to d9bb2b0142)