@tamyla/clodo-framework 3.1.22 → 3.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +230 -1
- package/dist/cli/commands/assess.js +192 -0
- package/dist/cli/commands/create.js +77 -0
- package/dist/{bin → cli}/commands/deploy.js +36 -14
- package/dist/cli/commands/diagnose.js +83 -0
- package/dist/{bin → cli}/commands/helpers/deployment-verification.js +2 -3
- package/dist/{bin → cli}/commands/helpers/error-recovery.js +1 -1
- package/dist/{bin → cli}/commands/helpers/resource-detection.js +1 -1
- package/dist/cli/commands/helpers.js +110 -0
- package/dist/cli/commands/init-config.js +57 -0
- package/dist/cli/commands/update.js +102 -0
- package/dist/cli/commands/validate.js +65 -0
- package/dist/cli/security-cli.js +118 -0
- package/dist/config/FeatureManager.js +6 -0
- package/dist/config/clodo-create.example.json +26 -0
- package/dist/config/clodo-deploy.example.json +41 -0
- package/dist/config/clodo-update.example.json +46 -0
- package/dist/config/clodo-validate.example.json +41 -0
- package/dist/config/customers/template/development.env.template +37 -0
- package/dist/config/customers/template/production.env.template +39 -0
- package/dist/config/customers/template/staging.env.template +37 -0
- package/dist/config/customers.js +625 -0
- package/dist/config/domain-examples/README.md +464 -0
- package/dist/config/domain-examples/environment-mapped.json +168 -0
- package/dist/config/domain-examples/multi-domain.json +144 -0
- package/dist/config/domain-examples/single-domain.json +50 -0
- package/dist/config/domains.js +186 -0
- package/dist/config/examples +12 -0
- package/dist/config/features.js +61 -0
- package/dist/config/index.js +6 -0
- package/dist/config/staging-deployment.json +60 -0
- package/dist/config/validation-config.json +347 -0
- package/dist/database/database-orchestrator.js +795 -0
- package/dist/database/index.js +4 -0
- package/dist/deployment/index.js +11 -0
- package/dist/deployment/orchestration/BaseDeploymentOrchestrator.js +426 -0
- package/dist/deployment/orchestration/PortfolioOrchestrator.js +273 -0
- package/dist/deployment/orchestration/SingleServiceOrchestrator.js +231 -0
- package/dist/deployment/orchestration/UnifiedDeploymentOrchestrator.js +662 -0
- package/dist/deployment/orchestration/index.js +17 -0
- package/dist/deployment/rollback-manager.js +36 -0
- package/dist/deployment/wrangler-deployer.js +640 -0
- package/dist/handlers/GenericRouteHandler.js +532 -0
- package/dist/lib/database/deployment-db-manager.js +423 -0
- package/dist/lib/database/wrangler-d1-manager.js +685 -0
- package/dist/lib/deployment/modules/DeploymentConfiguration.js +395 -0
- package/dist/lib/deployment/modules/DeploymentOrchestrator.js +492 -0
- package/dist/lib/deployment/modules/EnvironmentManager.js +517 -0
- package/dist/lib/deployment/modules/MonitoringIntegration.js +560 -0
- package/dist/lib/deployment/modules/ValidationManager.js +342 -0
- package/dist/lib/deployment/orchestration/BaseDeploymentOrchestrator.js +426 -0
- package/dist/lib/deployment/orchestration/EnterpriseOrchestrator.js +21 -0
- package/dist/lib/deployment/orchestration/PortfolioOrchestrator.js +273 -0
- package/dist/lib/deployment/orchestration/SingleServiceOrchestrator.js +231 -0
- package/dist/lib/deployment/orchestration/UnifiedDeploymentOrchestrator.js +662 -0
- package/dist/{bin → lib}/shared/cloudflare/domain-discovery.js +1 -1
- package/dist/{bin → lib}/shared/cloudflare/domain-manager.js +1 -1
- package/dist/{bin → lib}/shared/cloudflare/ops.js +4 -4
- package/dist/{bin → lib}/shared/config/command-config-manager.js +1 -1
- package/dist/{bin → lib}/shared/config/index.js +1 -1
- package/dist/{bin → lib}/shared/config/manifest-loader.js +3 -3
- package/dist/{bin → lib}/shared/deployment/credential-collector.js +1 -1
- package/dist/lib/shared/deployment/index.js +10 -0
- package/dist/{bin → lib}/shared/deployment/rollback-manager.js +1 -1
- package/dist/{bin → lib}/shared/deployment/utilities/d1-error-recovery.js +1 -1
- package/dist/{bin → lib}/shared/deployment/validator.js +1 -1
- package/dist/{bin → lib}/shared/deployment/workflows/interactive-database-workflow.js +1 -1
- package/dist/{bin → lib}/shared/monitoring/health-checker.js +2 -2
- package/dist/{bin → lib}/shared/routing/domain-router.js +1 -1
- package/dist/{bin → lib}/shared/utils/config-loader.js +47 -11
- package/dist/lib/shared/utils/service-config-manager.js +227 -0
- package/dist/{bin → lib}/shared/validation/ValidationRegistry.js +1 -1
- package/dist/migration/MigrationAdapters.js +608 -0
- package/dist/modules/ModuleManager.js +668 -0
- package/dist/modules/security.js +96 -0
- package/dist/orchestration/cross-domain-coordinator.js +1083 -0
- package/dist/orchestration/index.js +5 -0
- package/dist/orchestration/modules/DeploymentCoordinator.js +368 -0
- package/dist/orchestration/modules/DomainResolver.js +198 -0
- package/dist/orchestration/modules/StateManager.js +332 -0
- package/dist/orchestration/multi-domain-orchestrator.js +765 -0
- package/dist/routing/EnhancedRouter.js +158 -0
- package/dist/schema/SchemaManager.js +778 -0
- package/dist/security/index.js +2 -2
- package/dist/service-management/ConfirmationEngine.js +412 -0
- package/dist/service-management/ErrorTracker.js +299 -0
- package/dist/service-management/GenerationEngine.js +447 -0
- package/dist/service-management/InputCollector.js +619 -0
- package/dist/service-management/ServiceCreator.js +21 -0
- package/dist/service-management/ServiceOrchestrator.js +672 -0
- package/dist/service-management/generators/BaseGenerator.js +233 -0
- package/dist/service-management/generators/GeneratorRegistry.js +254 -0
- package/dist/service-management/generators/cicd/CiWorkflowGenerator.js +87 -0
- package/dist/service-management/generators/cicd/DeployWorkflowGenerator.js +106 -0
- package/dist/service-management/generators/code/ServiceHandlersGenerator.js +235 -0
- package/dist/service-management/generators/code/ServiceMiddlewareGenerator.js +116 -0
- package/dist/service-management/generators/code/ServiceUtilsGenerator.js +246 -0
- package/dist/service-management/generators/code/WorkerIndexGenerator.js +143 -0
- package/dist/service-management/generators/config/DevelopmentEnvGenerator.js +101 -0
- package/dist/service-management/generators/config/DomainsConfigGenerator.js +175 -0
- package/dist/service-management/generators/config/EnvExampleGenerator.js +178 -0
- package/dist/service-management/generators/config/ProductionEnvGenerator.js +97 -0
- package/dist/service-management/generators/config/StagingEnvGenerator.js +97 -0
- package/dist/service-management/generators/config/WranglerTomlGenerator.js +238 -0
- package/dist/service-management/generators/core/PackageJsonGenerator.js +243 -0
- package/dist/service-management/generators/core/SiteConfigGenerator.js +115 -0
- package/dist/service-management/generators/documentation/ApiDocsGenerator.js +331 -0
- package/dist/service-management/generators/documentation/ConfigurationDocsGenerator.js +294 -0
- package/dist/service-management/generators/documentation/DeploymentDocsGenerator.js +244 -0
- package/dist/service-management/generators/documentation/ReadmeGenerator.js +196 -0
- package/dist/service-management/generators/schemas/ServiceSchemaGenerator.js +190 -0
- package/dist/service-management/generators/scripts/DeployScriptGenerator.js +123 -0
- package/dist/service-management/generators/scripts/HealthCheckScriptGenerator.js +101 -0
- package/dist/service-management/generators/scripts/SetupScriptGenerator.js +88 -0
- package/dist/service-management/generators/service-types/StaticSiteGenerator.js +342 -0
- package/dist/service-management/generators/testing/EslintConfigGenerator.js +85 -0
- package/dist/service-management/generators/testing/IntegrationTestsGenerator.js +237 -0
- package/dist/service-management/generators/testing/JestConfigGenerator.js +72 -0
- package/dist/service-management/generators/testing/UnitTestsGenerator.js +277 -0
- package/dist/service-management/generators/tooling/DockerComposeGenerator.js +71 -0
- package/dist/service-management/generators/tooling/GitignoreGenerator.js +143 -0
- package/dist/service-management/generators/utils/FileWriter.js +179 -0
- package/dist/service-management/generators/utils/PathResolver.js +157 -0
- package/dist/service-management/generators/utils/ServiceManifestGenerator.js +111 -0
- package/dist/service-management/generators/utils/TemplateEngine.js +185 -0
- package/dist/service-management/generators/utils/index.js +18 -0
- package/dist/service-management/handlers/ConfirmationHandler.js +71 -0
- package/dist/service-management/handlers/GenerationHandler.js +80 -0
- package/dist/service-management/handlers/InputHandler.js +59 -0
- package/dist/service-management/handlers/ValidationHandler.js +216 -0
- package/dist/service-management/index.js +14 -0
- package/dist/service-management/routing/DomainRouteMapper.js +311 -0
- package/dist/service-management/routing/RouteGenerator.js +266 -0
- package/dist/service-management/routing/WranglerRoutesBuilder.js +273 -0
- package/dist/service-management/routing/index.js +14 -0
- package/dist/service-management/services/DirectoryStructureService.js +56 -0
- package/dist/service-management/services/GenerationCoordinator.js +208 -0
- package/dist/service-management/services/GeneratorRegistry.js +174 -0
- package/dist/services/GenericDataService.js +501 -0
- package/dist/ui-structures/concepts/second-order-acquisition-strategy.md +286 -0
- package/dist/ui-structures/concepts/service-lifecycle-management.md +150 -0
- package/dist/ui-structures/concepts/service-manifest-guide.md +309 -0
- package/dist/ui-structures/concepts/three-tier-categorization-strategy.md +231 -0
- package/dist/ui-structures/creation/automated-generation-ui.json +246 -0
- package/dist/ui-structures/creation/core-inputs-ui.json +217 -0
- package/dist/ui-structures/creation/smart-confirmable-ui.json +451 -0
- package/dist/ui-structures/reference/absolutely-required-inputs.json +315 -0
- package/dist/ui-structures/reference/service-manifest-template.json +342 -0
- package/dist/utils/cloudflare/ops.js +1 -1
- package/dist/utils/file-manager.js +1 -1
- package/dist/utils/formatters.js +1 -1
- package/dist/utils/logger.js +1 -1
- package/dist/version/VersionDetector.js +813 -0
- package/dist/worker/index.js +4 -0
- package/dist/worker/integration.js +351 -0
- package/package.json +7 -15
- package/dist/bin/commands/validate.js +0 -51
- package/dist/bin/security/security-cli.js +0 -108
- package/dist/bin/shared/deployment/index.js +0 -10
- /package/dist/{bin → cli}/clodo-service.js +0 -0
- /package/dist/{bin → cli}/commands/helpers/deployment-ui.js +0 -0
- /package/dist/{bin → lib}/shared/cache/configuration-cache.js +0 -0
- /package/dist/{bin → lib}/shared/cloudflare/index.js +0 -0
- /package/dist/{bin → lib}/shared/config/ConfigurationManager.js +0 -0
- /package/dist/{bin → lib}/shared/config/cache.js +0 -0
- /package/dist/{bin → lib}/shared/config/cloudflare-service-validator.js +0 -0
- /package/dist/{bin → lib}/shared/config/manager.js +0 -0
- /package/dist/{bin → lib}/shared/database/connection-manager.js +0 -0
- /package/dist/{bin → lib}/shared/database/index.js +0 -0
- /package/dist/{bin → lib}/shared/database/orchestrator.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/auditor.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/workflows/deployment-summary.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/workflows/interactive-confirmation.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/workflows/interactive-domain-info-gatherer.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/workflows/interactive-secret-workflow.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/workflows/interactive-testing-workflow.js +0 -0
- /package/dist/{bin → lib}/shared/deployment/workflows/interactive-validation.js +0 -0
- /package/dist/{bin → lib}/shared/error-handling/error-classifier.js +0 -0
- /package/dist/{bin → lib}/shared/index.js +0 -0
- /package/dist/{bin → lib}/shared/logging/Logger.js +0 -0
- /package/dist/{bin → lib}/shared/monitoring/index.js +0 -0
- /package/dist/{bin → lib}/shared/monitoring/memory-manager.js +0 -0
- /package/dist/{bin → lib}/shared/monitoring/production-monitor.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/api-tester.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/auth-tester.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/core.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/database-tester.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/index.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/load-tester.js +0 -0
- /package/dist/{bin → lib}/shared/production-tester/performance-tester.js +0 -0
- /package/dist/{bin → lib}/shared/security/api-token-manager.js +0 -0
- /package/dist/{bin → lib}/shared/security/index.js +0 -0
- /package/dist/{bin → lib}/shared/security/secret-generator.js +0 -0
- /package/dist/{bin → lib}/shared/security/secure-token-manager.js +0 -0
- /package/dist/{bin → lib}/shared/utils/ErrorHandler.js +0 -0
- /package/dist/{bin → lib}/shared/utils/cli-options.js +0 -0
- /package/dist/{bin → lib}/shared/utils/deployment-validator.js +0 -0
- /package/dist/{bin → lib}/shared/utils/error-recovery.js +0 -0
- /package/dist/{bin → lib}/shared/utils/file-manager.js +0 -0
- /package/dist/{bin → lib}/shared/utils/formatters.js +0 -0
- /package/dist/{bin → lib}/shared/utils/graceful-shutdown-manager.js +0 -0
- /package/dist/{bin → lib}/shared/utils/index.js +0 -0
- /package/dist/{bin → lib}/shared/utils/interactive-prompts.js +0 -0
- /package/dist/{bin → lib}/shared/utils/interactive-utils.js +0 -0
- /package/dist/{bin → lib}/shared/utils/output-formatter.js +0 -0
- /package/dist/{bin → lib}/shared/utils/progress-manager.js +0 -0
- /package/dist/{bin → lib}/shared/utils/progress-spinner.js +0 -0
- /package/dist/{bin → lib}/shared/utils/rate-limiter.js +0 -0
- /package/dist/{bin → lib}/shared/utils/sensitive-redactor.js +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ErrorTracker - Comprehensive Error Handling and Recovery System
|
|
3
|
+
*
|
|
4
|
+
* Captures failures, tracks input states, and provides recovery mechanisms
|
|
5
|
+
* for the Clodo Framework service lifecycle management.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'fs/promises';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { logger } from '../lib/shared/logging/Logger.js';
|
|
12
|
+
export class ErrorTracker {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.errors = [];
|
|
15
|
+
this.errorLogPath = './clodo-service-errors.log';
|
|
16
|
+
this.maxErrors = 100; // Keep last 100 errors
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Capture an error with context and input state
|
|
21
|
+
*/
|
|
22
|
+
captureError(error, context = {}) {
|
|
23
|
+
const errorEntry = {
|
|
24
|
+
timestamp: new Date().toISOString(),
|
|
25
|
+
error: {
|
|
26
|
+
message: error.message,
|
|
27
|
+
stack: error.stack,
|
|
28
|
+
name: error.name
|
|
29
|
+
},
|
|
30
|
+
context: {
|
|
31
|
+
command: context.command || 'unknown',
|
|
32
|
+
servicePath: context.servicePath || process.cwd(),
|
|
33
|
+
inputState: context.inputState || {},
|
|
34
|
+
userInputs: context.userInputs || {},
|
|
35
|
+
action: context.action || 'unknown',
|
|
36
|
+
options: context.options || {}
|
|
37
|
+
},
|
|
38
|
+
recovery: this.generateRecoverySuggestions(error, context),
|
|
39
|
+
severity: this.determineSeverity(error, context)
|
|
40
|
+
};
|
|
41
|
+
this.errors.push(errorEntry);
|
|
42
|
+
|
|
43
|
+
// Keep only recent errors
|
|
44
|
+
if (this.errors.length > this.maxErrors) {
|
|
45
|
+
this.errors = this.errors.slice(-this.maxErrors);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Log to file asynchronously (don't block)
|
|
49
|
+
this.logErrorToFile(errorEntry).catch(err => {
|
|
50
|
+
logger.warn('Failed to write error log', {
|
|
51
|
+
error: err.message
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return errorEntry;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Generate recovery suggestions based on error type and context
|
|
59
|
+
*/
|
|
60
|
+
generateRecoverySuggestions(error, context) {
|
|
61
|
+
const suggestions = [];
|
|
62
|
+
|
|
63
|
+
// Network/API errors
|
|
64
|
+
if (error.message.includes('fetch') || error.message.includes('network') || error.message.includes('API')) {
|
|
65
|
+
suggestions.push('Check your internet connection');
|
|
66
|
+
suggestions.push('Verify Cloudflare API token is valid and has required permissions');
|
|
67
|
+
suggestions.push('Confirm Cloudflare account and zone IDs are correct');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Authentication errors
|
|
71
|
+
if (error.message.includes('auth') || error.message.includes('token') || error.message.includes('401') || error.message.includes('403')) {
|
|
72
|
+
suggestions.push('Verify Cloudflare API token has not expired');
|
|
73
|
+
suggestions.push('Check that the token has permissions for the required operations');
|
|
74
|
+
suggestions.push('Regenerate API token if necessary');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// File system errors
|
|
78
|
+
if (error.message.includes('ENOENT') || error.message.includes('permission') || error.message.includes('access')) {
|
|
79
|
+
suggestions.push('Check file permissions on the service directory');
|
|
80
|
+
suggestions.push('Ensure you have write access to the target directory');
|
|
81
|
+
suggestions.push('Verify the service path exists and is accessible');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Validation errors
|
|
85
|
+
if (error.message.includes('validation') || error.message.includes('invalid')) {
|
|
86
|
+
suggestions.push('Review input values for correctness');
|
|
87
|
+
suggestions.push('Use clodo-service validate <path> to check service configuration');
|
|
88
|
+
suggestions.push('Run clodo-service diagnose <path> for detailed issue analysis');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Configuration errors
|
|
92
|
+
if (error.message.includes('config') || error.message.includes('configuration')) {
|
|
93
|
+
suggestions.push('Run clodo-service update --fix-errors to attempt automatic fixes');
|
|
94
|
+
suggestions.push('Check domain configuration in src/config/domains.js');
|
|
95
|
+
suggestions.push('Verify package.json has all required fields');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Template errors
|
|
99
|
+
if (error.message.includes('template') || error.message.includes('variable')) {
|
|
100
|
+
suggestions.push('Check that all required template variables are provided');
|
|
101
|
+
suggestions.push('Verify template files exist and are readable');
|
|
102
|
+
suggestions.push('Regenerate service with clodo-service update --regenerate-configs');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Service creation/update specific
|
|
106
|
+
if (context.action === 'create' || context.action === 'update') {
|
|
107
|
+
suggestions.push('Try running the command again with --non-interactive flag');
|
|
108
|
+
suggestions.push('Use clodo-service diagnose to identify specific issues');
|
|
109
|
+
suggestions.push('Check that service name follows naming conventions (lowercase, hyphens only)');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Cloudflare specific
|
|
113
|
+
if (context.action && context.action.includes('cloudflare')) {
|
|
114
|
+
suggestions.push('Verify Cloudflare account has D1 database enabled');
|
|
115
|
+
suggestions.push('Check zone ID corresponds to the correct domain');
|
|
116
|
+
suggestions.push('Ensure API token has D1:Edit permission');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Add generic suggestions if none specific found
|
|
120
|
+
if (suggestions.length === 0) {
|
|
121
|
+
suggestions.push('Check the error message for specific details');
|
|
122
|
+
suggestions.push('Review the Clodo Framework documentation');
|
|
123
|
+
suggestions.push('Try the operation again after reviewing inputs');
|
|
124
|
+
suggestions.push('Contact support if the issue persists');
|
|
125
|
+
}
|
|
126
|
+
return suggestions;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Determine error severity level
|
|
131
|
+
*/
|
|
132
|
+
determineSeverity(error, context) {
|
|
133
|
+
// Critical errors that prevent operation
|
|
134
|
+
if (error.message.includes('authentication') || error.message.includes('permission') || error.message.includes('access denied') || error.message.includes('critical')) {
|
|
135
|
+
return 'critical';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// High severity - operation fails but may be recoverable
|
|
139
|
+
if (error.message.includes('network') || error.message.includes('timeout') || error.message.includes('connection') || error.message.includes('validation')) {
|
|
140
|
+
return 'high';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Medium severity - partial failure or warnings
|
|
144
|
+
if (error.message.includes('warning') || error.message.includes('deprecated') || error.message.includes('not found')) {
|
|
145
|
+
return 'medium';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Low severity - minor issues
|
|
149
|
+
return 'low';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Log error to file
|
|
154
|
+
*/
|
|
155
|
+
async logErrorToFile(errorEntry) {
|
|
156
|
+
try {
|
|
157
|
+
const logEntry = JSON.stringify(errorEntry, null, 2) + '\n---\n';
|
|
158
|
+
await fs.appendFile(this.errorLogPath, logEntry);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
// If we can't write to the log file, at least show a warning
|
|
161
|
+
logger.warn('Could not write to error log', {
|
|
162
|
+
error: error.message
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Get recent errors
|
|
169
|
+
*/
|
|
170
|
+
getRecentErrors(limit = 10) {
|
|
171
|
+
return this.errors.slice(-limit);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get errors by severity
|
|
176
|
+
*/
|
|
177
|
+
getErrorsBySeverity(severity) {
|
|
178
|
+
return this.errors.filter(error => error.severity === severity);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get errors by command
|
|
183
|
+
*/
|
|
184
|
+
getErrorsByCommand(command) {
|
|
185
|
+
return this.errors.filter(error => error.context.command === command);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Clear error history
|
|
190
|
+
*/
|
|
191
|
+
clearErrors() {
|
|
192
|
+
this.errors = [];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Export error report
|
|
197
|
+
*/
|
|
198
|
+
async exportErrorReport(filePath) {
|
|
199
|
+
const report = {
|
|
200
|
+
generated: new Date().toISOString(),
|
|
201
|
+
totalErrors: this.errors.length,
|
|
202
|
+
errorsBySeverity: {
|
|
203
|
+
critical: this.getErrorsBySeverity('critical').length,
|
|
204
|
+
high: this.getErrorsBySeverity('high').length,
|
|
205
|
+
medium: this.getErrorsBySeverity('medium').length,
|
|
206
|
+
low: this.getErrorsBySeverity('low').length
|
|
207
|
+
},
|
|
208
|
+
recentErrors: this.getRecentErrors(20),
|
|
209
|
+
summary: this.generateErrorSummary()
|
|
210
|
+
};
|
|
211
|
+
await fs.writeFile(filePath, JSON.stringify(report, null, 2), 'utf8');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Generate error summary
|
|
216
|
+
*/
|
|
217
|
+
generateErrorSummary() {
|
|
218
|
+
const summary = {
|
|
219
|
+
mostCommonErrors: [],
|
|
220
|
+
mostProblematicCommands: [],
|
|
221
|
+
recentTrends: 'Analysis not implemented yet'
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// Count error types
|
|
225
|
+
const errorCounts = {};
|
|
226
|
+
this.errors.forEach(error => {
|
|
227
|
+
const key = error.error.name || 'Unknown';
|
|
228
|
+
errorCounts[key] = (errorCounts[key] || 0) + 1;
|
|
229
|
+
});
|
|
230
|
+
summary.mostCommonErrors = Object.entries(errorCounts).sort(([, a], [, b]) => b - a).slice(0, 5).map(([type, count]) => ({
|
|
231
|
+
type,
|
|
232
|
+
count
|
|
233
|
+
}));
|
|
234
|
+
|
|
235
|
+
// Count problematic commands
|
|
236
|
+
const commandCounts = {};
|
|
237
|
+
this.errors.forEach(error => {
|
|
238
|
+
const command = error.context.command || 'unknown';
|
|
239
|
+
commandCounts[command] = (commandCounts[command] || 0) + 1;
|
|
240
|
+
});
|
|
241
|
+
summary.mostProblematicCommands = Object.entries(commandCounts).sort(([, a], [, b]) => b - a).slice(0, 5).map(([command, count]) => ({
|
|
242
|
+
command,
|
|
243
|
+
count
|
|
244
|
+
}));
|
|
245
|
+
return summary;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Display error summary to console
|
|
250
|
+
*/
|
|
251
|
+
displayErrorSummary() {
|
|
252
|
+
const summary = this.generateErrorSummary();
|
|
253
|
+
console.log(chalk.cyan('\n📊 Error Summary'));
|
|
254
|
+
console.log(chalk.white(`Total Errors: ${this.errors.length}`));
|
|
255
|
+
if (summary.mostCommonErrors.length > 0) {
|
|
256
|
+
console.log(chalk.cyan('\nMost Common Errors:'));
|
|
257
|
+
summary.mostCommonErrors.forEach(({
|
|
258
|
+
type,
|
|
259
|
+
count
|
|
260
|
+
}) => {
|
|
261
|
+
console.log(chalk.white(` ${type}: ${count} times`));
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
if (summary.mostProblematicCommands.length > 0) {
|
|
265
|
+
console.log(chalk.cyan('\nMost Problematic Commands:'));
|
|
266
|
+
summary.mostProblematicCommands.forEach(({
|
|
267
|
+
command,
|
|
268
|
+
count
|
|
269
|
+
}) => {
|
|
270
|
+
console.log(chalk.white(` ${command}: ${count} errors`));
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Attempt automatic error recovery
|
|
277
|
+
*/
|
|
278
|
+
async attemptRecovery(errorEntry) {
|
|
279
|
+
const recoveries = [];
|
|
280
|
+
try {
|
|
281
|
+
// Try common recovery actions based on error type
|
|
282
|
+
if (errorEntry.error.message.includes('permission') || errorEntry.error.message.includes('access')) {
|
|
283
|
+
// Try to fix permissions (limited in what we can do)
|
|
284
|
+
recoveries.push('Checked permissions - manual intervention may be required');
|
|
285
|
+
}
|
|
286
|
+
if (errorEntry.error.message.includes('network') || errorEntry.error.message.includes('timeout')) {
|
|
287
|
+
// Wait and retry logic could be implemented here
|
|
288
|
+
recoveries.push('Network error detected - consider retrying the operation');
|
|
289
|
+
}
|
|
290
|
+
if (errorEntry.context.action === 'validate' || errorEntry.context.action === 'create') {
|
|
291
|
+
// Try to validate/fix configuration
|
|
292
|
+
recoveries.push('Consider running clodo-service update --fix-errors');
|
|
293
|
+
}
|
|
294
|
+
} catch (recoveryError) {
|
|
295
|
+
recoveries.push(`Recovery attempt failed: ${recoveryError.message}`);
|
|
296
|
+
}
|
|
297
|
+
return recoveries;
|
|
298
|
+
}
|
|
299
|
+
}
|