(error: PluginError)
| 1 | import { getPluginErrorMessage, type PluginError } from '../../types/plugin.js'; |
| 2 | export function formatErrorMessage(error: PluginError): string { |
| 3 | switch (error.type) { |
| 4 | case 'path-not-found': |
| 5 | return `${error.component} path not found: ${error.path}`; |
| 6 | case 'git-auth-failed': |
| 7 | return `Git ${error.authType.toUpperCase()} authentication failed for ${error.gitUrl}`; |
| 8 | case 'git-timeout': |
| 9 | return `Git ${error.operation} timed out for ${error.gitUrl}`; |
| 10 | case 'network-error': |
| 11 | return `Network error accessing ${error.url}${error.details ? `: ${error.details}` : ''}`; |
| 12 | case 'manifest-parse-error': |
| 13 | return `Failed to parse manifest at ${error.manifestPath}: ${error.parseError}`; |
| 14 | case 'manifest-validation-error': |
| 15 | return `Invalid manifest at ${error.manifestPath}: ${error.validationErrors.join(', ')}`; |
| 16 | case 'plugin-not-found': |
| 17 | return `Plugin "${error.pluginId}" not found in marketplace "${error.marketplace}"`; |
| 18 | case 'marketplace-not-found': |
| 19 | return `Marketplace "${error.marketplace}" not found`; |
| 20 | case 'marketplace-load-failed': |
| 21 | return `Failed to load marketplace "${error.marketplace}": ${error.reason}`; |
| 22 | case 'mcp-config-invalid': |
| 23 | return `Invalid MCP server config for "${error.serverName}": ${error.validationError}`; |
| 24 | case 'mcp-server-suppressed-duplicate': |
| 25 | { |
| 26 | const dup = error.duplicateOf.startsWith('plugin:') ? `server provided by plugin "${error.duplicateOf.split(':')[1] ?? '?'}"` : `already-configured "${error.duplicateOf}"`; |
| 27 | return `MCP server "${error.serverName}" skipped — same command/URL as ${dup}`; |
| 28 | } |
| 29 | case 'hook-load-failed': |
| 30 | return `Failed to load hooks from ${error.hookPath}: ${error.reason}`; |
| 31 | case 'component-load-failed': |
| 32 | return `Failed to load ${error.component} from ${error.path}: ${error.reason}`; |
| 33 | case 'mcpb-download-failed': |
| 34 | return `Failed to download MCPB from ${error.url}: ${error.reason}`; |
| 35 | case 'mcpb-extract-failed': |
| 36 | return `Failed to extract MCPB ${error.mcpbPath}: ${error.reason}`; |
| 37 | case 'mcpb-invalid-manifest': |
| 38 | return `MCPB manifest invalid at ${error.mcpbPath}: ${error.validationError}`; |
| 39 | case 'marketplace-blocked-by-policy': |
| 40 | return error.blockedByBlocklist ? `Marketplace "${error.marketplace}" is blocked by enterprise policy` : `Marketplace "${error.marketplace}" is not in the allowed marketplace list`; |
| 41 | case 'dependency-unsatisfied': |
| 42 | return error.reason === 'not-enabled' ? `Dependency "${error.dependency}" is disabled` : `Dependency "${error.dependency}" is not installed`; |
| 43 | case 'lsp-config-invalid': |
| 44 | return `Invalid LSP server config for "${error.serverName}": ${error.validationError}`; |
| 45 | case 'lsp-server-start-failed': |
| 46 | return `LSP server "${error.serverName}" failed to start: ${error.reason}`; |
| 47 | case 'lsp-server-crashed': |
| 48 | return error.signal ? `LSP server "${error.serverName}" crashed with signal ${error.signal}` : `LSP server "${error.serverName}" crashed with exit code ${error.exitCode ?? 'unknown'}`; |
| 49 | case 'lsp-request-timeout': |
| 50 | return `LSP server "${error.serverName}" timed out on ${error.method} after ${error.timeoutMs}ms`; |
| 51 | case 'lsp-request-failed': |
| 52 | return `LSP server "${error.serverName}" ${error.method} failed: ${error.error}`; |
| 53 | case 'plugin-cache-miss': |
| 54 | return `Plugin "${error.plugin}" not cached at ${error.installPath}`; |
| 55 | case 'generic-error': |
| 56 | return error.error; |
| 57 | } |
| 58 | const _exhaustive: never = error; |
| 59 | return getPluginErrorMessage(_exhaustive); |
| 60 | } |
no test coverage detected