infiniflow/ragflow · error · Error

Failed to get version folder ID

Error message

Failed to get version folder ID

What it means

Thrown in web/src/pages/skills/hooks.ts:843 when the version-folder creation call returned code 0 but data.id is missing (versionFolderId falsy). It is a response-shape guard: the backend claims success yet the id needed to place files is absent, so continuing would upload files to an unknown parent.

Source

Thrown at web/src/pages/skills/hooks.ts:843

        }

        if (!skillFolderId) throw new Error('Failed to get skill folder ID');

        // Create version folder
        const versionRes = await fileManagerService.createFolder({
          name: version,
          type: 'folder',
          parent_id: skillFolderId,
        });

        if (versionRes.data.code !== 0) {
          throw new Error('Failed to create version folder');
        }

        const versionFolderId = versionRes.data.data?.id;

        if (!versionFolderId)
          throw new Error('Failed to get version folder ID');

        // Upload files recursively to preserve directory structure
        const uploadFileWithStructure = async (
          file: File,
          parentId: string,
        ) => {
          const relativePath = (file as any).webkitRelativePath || file.name;
          const pathParts = relativePath.split('/');

          // If file is in root directory (no subdirectories)
          if (pathParts.length === 1) {
            const formData = new FormData();
            formData.append('parent_id', parentId);
            formData.append('file', file);
            await fileManagerService.uploadFile(formData);
            return;
          }

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Log the full versionRes payload to confirm which field carries the id in the current API
  2. Update the typing of createFolder's response to match the backend (e.g. data.id vs data.data.id)
  3. If id is genuinely absent, re-list the parent and match by version name to recover the id
  4. Fail fast with a specific message naming the version that failed

Example fix

// before
const versionFolderId = versionRes.data.data?.id;
if (!versionFolderId)
  throw new Error('Failed to get version folder ID');

// after
let versionFolderId = versionRes.data.data?.id;
if (!versionFolderId) {
  const { data: relist } = await fileManagerService.listFile({
    parent_id: skillFolderId,
  });
  versionFolderId = (relist.data?.files || []).find(
    (f: any) => f.type === 'folder' && f.name === version,
  )?.id;
}
if (!versionFolderId)
  throw new Error(`Failed to get version folder ID for ${version}`);
Defensive patterns

Strategy: fallback

Validate before calling

const versionIdOrRecover = async (res: any, skillFolderId: string, version: string) => {
  const id = res?.data?.data?.id;
  if (id) return id;
  const list = await fileManagerService.listFile({ parent_id: skillFolderId });
  return (list.data?.files || []).find((f) => f.name === version)?.id ?? null;
};

Type guard

const isFolderId = (v: unknown): v is string => typeof v === 'string' && v.length > 0;

Prevention

When it happens

Trigger: Backend createFolder response omits data.id after an API change; proxy truncates the JSON; a mocked/stubbed service in tests returns {code: 0} only; race where the created folder is immediately deleted and a follow-up fetch returns no id.

Common situations: Frontend/backend version skew after upgrading only one side. Test doubles not matching the real contract. Unusual gateway buffering stripping parts of the body.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/ceb34086badde818. Report an issue: GitHub.