google-gemini/gemini-cli · error

The path "${trimmedPath}" is not a directory.

Error message

The path "${trimmedPath}" is not a directory.

What it means

After confirming the resolved path is within the allowed root, the function stats it. If the path exists on disk but is not a directory (e.g., a regular file, socket, device node), it throws because a workspace path must resolve to a directory.

Source

Thrown at packages/a2a-server/src/utils/path_utils.ts:52

    const resolvedWorkspacePath = path.resolve(
      canonicalAllowedRoot,
      trimmedPath,
    );
    const canonicalWorkspacePath = resolveToRealPath(resolvedWorkspacePath);

    // Check if the resolved path is within the allowed root directory
    if (
      canonicalWorkspacePath !== canonicalAllowedRoot &&
      !isSubpath(canonicalAllowedRoot, canonicalWorkspacePath)
    ) {
      throw new Error(
        `Security violation: The path "${trimmedPath}" is outside the allowed root directory.`,
      );
    }

    const stats = await fs.promises.stat(canonicalWorkspacePath);
    if (!stats.isDirectory()) {
      throw new Error(`The path "${trimmedPath}" is not a directory.`);
    }

    return canonicalWorkspacePath;
  } catch (e) {
    if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
      throw new Error(`The path "${trimmedPath}" does not exist.`);
    }
    throw e; // Re-throw other errors
  }
}

View on GitHub (pinned to 5024443c72)

Solutions

  1. Verify the path points to a directory, not a file.
  2. Create the directory before validation if it should exist.
  3. Correct the path to reference the intended folder.
Defensive patterns

Strategy: validation

Validate before calling

import * as fs from 'node:fs';

async function isDirectory(path: string): Promise<boolean> {
  try {
    const stats = await fs.promises.stat(path);
    return stats.isDirectory();
  } catch {
    return false;
  }
}

// Before calling validateWorkspacePath with a known absolute path:
if (!(await isDirectory(resolvedPath))) {
  throw new Error('Expected a directory but found a file or other type.');
}

Prevention

When it happens

Trigger: Calling validateWorkspacePath('config.json') where config.json is a regular file within the root, or pointing to any non-directory filesystem entry.

Common situations: Pointing to a file instead of a folder; typo in the path resolving to an existing file; the intended directory was replaced by a file of the same name.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/ebc725019081613c. Report an issue: GitHub.