{"record":{"id":"a980ee9ff309ebfd","repo":"davila7/claude-code-templates","slug":"warning-error-counting-components-for-plugin-at","errorCode":null,"errorMessage":"Warning: Error counting components for plugin at ${pluginPath}","messagePattern":"Warning: Error counting components for plugin at (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-tool/src/plugin-dashboard.js","lineNumber":350,"sourceCode":"        const commandFiles = await fs.readdir(commandsDir);\n        components.commands = commandFiles.filter(f => f.endsWith('.md')).length;\n      }\n\n      // Count hooks\n      const hooksFile = path.join(pluginPath, 'hooks', 'hooks.json');\n      if (await fs.pathExists(hooksFile)) {\n        const hooksData = JSON.parse(await fs.readFile(hooksFile, 'utf8'));\n        components.hooks = Object.values(hooksData.hooks || {}).flat().length;\n      }\n\n      // Count MCPs\n      const mcpFile = path.join(pluginPath, '.mcp.json');\n      if (await fs.pathExists(mcpFile)) {\n        const mcpData = JSON.parse(await fs.readFile(mcpFile, 'utf8'));\n        components.mcps = Object.keys(mcpData.mcpServers || {}).length;\n      }\n    } catch (error) {\n      console.warn(chalk.yellow(`Warning: Error counting components for plugin at ${pluginPath}`), error.message);\n    }\n\n    return components;\n  }\n\n  async loadPermissions() {\n    const permissions = {\n      agents: [],\n      commands: [],\n      hooks: [],\n      mcps: []\n    };\n\n    try {\n      // Load user-level permissions\n      const userPermissions = await this.loadUserPermissions();\n\n      // Load plugin permissions","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/plugin-dashboard.js#L332-L368","documentation":"countPluginComponents wraps its per-plugin component counting (agents/, commands/, skills/, hooks, .mcp.json) in a try/catch and warns when any step fails. The most common cause is JSON.parse throwing on a malformed .mcp.json inside the plugin directory, but fs/path errors on unexpected file layouts also trigger it. The function degrades gracefully, returning whatever component counts were accumulated before the error.","triggerScenarios":"Calling countPluginComponents on a plugin directory whose .mcp.json exists but contains invalid JSON (comments, trailing commas, empty file), or whose internal directory structure violates assumptions (a file where a directory is expected, unreadable files due to permissions).","commonSituations":"Plugin author left a commented-out or empty .mcp.json; .mcp.json created by a tool that writes JSON5 or YAML; plugin installed partially so .mcp.json is truncated; file permissions broken after copying a plugin between machines.","solutions":["Run `jq . .mcp.json` (or `node -e \"JSON.parse(require('fs').readFileSync('.mcp.json'))\"`) inside the plugin dir to find the syntax error","Fix or delete the malformed .mcp.json — an absent file is skipped cleanly, a corrupt one warns","Reinstall the plugin from its source to restore a complete, valid file","Check file readability (`ls -la`) if the JSON is valid but the error persists"],"exampleFix":"// before\n// .mcp.json contains: { \"mcpServers\": { \"x\": {} }, } // trailing comma\n// after\n{ \"mcpServers\": { \"x\": {} } }","handlingStrategy":"validation","validationCode":"async function mcpJsonValid(pluginPath) {\n  const p = path.join(pluginPath, '.mcp.json');\n  if (!(await fs.pathExists(p))) return true; // absent is fine\n  try { JSON.parse(await fs.readFile(p, 'utf8')); return true; }\n  catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"catch (error) {\n  if (error instanceof SyntaxError) console.warn(`Malformed .mcp.json in ${pluginPath}`);\n  return components; // keep partial counts\n}","preventionTips":["Never put comments or trailing commas in .mcp.json","Run `jq . .mcp.json` in CI for every plugin you author","Delete rather than empty the file if a plugin has no MCPs"],"tags":["json-parse","mcp-json","plugin","component-count"],"backgroundTag":"json-parse-error","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}