affaan-m/ECC · error · Error

Expected a directory: ${dirPath}

Error message

Expected a directory: ${dirPath}

What it means

Thrown by ensureDirectory() in scripts/gemini-adapt-agents.js when the path exists (passes existsSync) but is not a directory — fs.statSync().isDirectory() returns false. This catches cases where the path points to a file, symlink to a file, or other non-directory filesystem entry.

Source

Thrown at scripts/gemini-adapt-agents.js:53

  const positional = argv.filter(arg => !arg.startsWith('-'));
  if (positional.length > 1) {
    throw new Error('Expected at most one agents directory argument');
  }

  return {
    help: false,
    agentsDir: path.resolve(positional[0] || path.join(process.cwd(), '.gemini', 'agents')),
  };
}

function ensureDirectory(dirPath) {
  if (!fs.existsSync(dirPath)) {
    throw new Error(`Agents directory not found: ${dirPath}`);
  }

  if (!fs.statSync(dirPath).isDirectory()) {
    throw new Error(`Expected a directory: ${dirPath}`);
  }
}

function parseToolList(line) {
  const match = line.match(/^\s*tools\s*:\s*(.*)$/);
  if (!match) {
    return null;
  }

  return normalizeAgentTools(match[1]);
}

function adaptToolName(toolName) {
  const mapped = TOOL_NAME_MAP.get(toolName);
  if (mapped) {
    return mapped;
  }

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Ensure the path points to a directory, not a file.
  2. If you passed an agent file path, use its parent directory instead.
  3. Check with `ls -la <path>` to confirm it is a directory.
  4. Remove or rename the conflicting file if it was created by mistake.

Example fix

// before
node scripts/gemini-adapt-agents.js .gemini/agents/my-agent.md
// after
node scripts/gemini-adapt-agents.js .gemini/agents
Defensive patterns

Strategy: validation

Validate before calling

const stat = fs.statSync(dirPath);
if (!stat.isDirectory()) {
  console.error(`Path is not a directory: ${dirPath}. Use the parent directory, not a file.`);
  process.exit(1);
}

Type guard

function isDirectory(p) {
  try { return fs.statSync(p).isDirectory(); } catch { return false; }
}

Prevention

When it happens

Trigger: Passing a path that resolves to a regular file (e.g. `node scripts/gemini-adapt-agents.js .gemini/agents/some-agent.md`) instead of the parent directory, or pointing at a named pipe/socket.

Common situations: User passes an individual agent file path instead of the directory, or a stale symlink points to a file. Also common when the default `.gemini/agents` is accidentally a file created by a misconfigured tool.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/cbc6c41ed96bcfea. Report an issue: GitHub.