* Generic error handler for plugin CLI commands. Emits * tengu_plugin_command_failed before exit so dashboards can compute a * success rate against the corresponding success events.
( error: unknown, command: PluginCliCommand, plugin?: string, )
| 51 | * success rate against the corresponding success events. |
| 52 | */ |
| 53 | function handlePluginCommandError( |
| 54 | error: unknown, |
| 55 | command: PluginCliCommand, |
| 56 | plugin?: string, |
| 57 | ): never { |
| 58 | logError(error) |
| 59 | const operation = plugin |
| 60 | ? `${command} plugin "${plugin}"` |
| 61 | : command === 'disable-all' |
| 62 | ? 'disable all plugins' |
| 63 | : `${command} plugins` |
| 64 | // biome-ignore lint/suspicious/noConsole:: intentional console output |
| 65 | console.error( |
| 66 | `${figures.cross} Failed to ${operation}: ${errorMessage(error)}`, |
| 67 | ) |
| 68 | const telemetryFields = plugin |
| 69 | ? (() => { |
| 70 | const { name, marketplace } = parsePluginIdentifier(plugin) |
| 71 | return { |
| 72 | _PROTO_plugin_name: |
| 73 | name as AnalyticsMetadata_I_VERIFIED_THIS_IS_PII_TAGGED, |
| 74 | ...(marketplace && { |
| 75 | _PROTO_marketplace_name: |
| 76 | marketplace as AnalyticsMetadata_I_VERIFIED_THIS_IS_PII_TAGGED, |
| 77 | }), |
| 78 | ...buildPluginTelemetryFields( |
| 79 | name, |
| 80 | marketplace, |
| 81 | getManagedPluginNames(), |
| 82 | ), |
| 83 | } |
| 84 | })() |
| 85 | : {} |
| 86 | logEvent('tengu_plugin_command_failed', { |
| 87 | command: |
| 88 | command as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 89 | error_category: classifyPluginCommandError( |
| 90 | error, |
| 91 | ) as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 92 | ...telemetryFields, |
| 93 | }) |
| 94 | // eslint-disable-next-line custom-rules/no-process-exit |
| 95 | process.exit(1) |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * CLI command: Install a plugin non-interactively |
no test coverage detected