@silasfmartins/testhub 1.0.0
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/.github/copilot-instructions.md +520 -0
- package/biome.json +37 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +169 -0
- package/dist/scripts/consumer-postinstall.d.ts +15 -0
- package/dist/scripts/consumer-postinstall.js +785 -0
- package/dist/scripts/generate-docs.d.ts +16 -0
- package/dist/scripts/generate-docs.js +1363 -0
- package/dist/scripts/generate-index.d.ts +2 -0
- package/dist/scripts/generate-index.js +314 -0
- package/dist/scripts/init-api.d.ts +2 -0
- package/dist/scripts/init-api.js +525 -0
- package/dist/scripts/init-banco.d.ts +2 -0
- package/dist/scripts/init-banco.js +347 -0
- package/dist/scripts/init-frontend.d.ts +2 -0
- package/dist/scripts/init-frontend.js +627 -0
- package/dist/scripts/init-mobile.d.ts +2 -0
- package/dist/scripts/init-mobile.js +481 -0
- package/dist/scripts/init-scenarios.d.ts +2 -0
- package/dist/scripts/init-scenarios.js +846 -0
- package/dist/scripts/init-ssh.d.ts +2 -0
- package/dist/scripts/init-ssh.js +639 -0
- package/dist/scripts/package-versions.d.ts +57 -0
- package/dist/scripts/package-versions.js +768 -0
- package/dist/scripts/postinstall.d.ts +1 -0
- package/dist/scripts/postinstall.js +527 -0
- package/dist/scripts/robust-build.d.ts +7 -0
- package/dist/scripts/robust-build.js +88 -0
- package/dist/scripts/setup-local-packages.d.ts +31 -0
- package/dist/scripts/setup-local-packages.js +237 -0
- package/dist/scripts/smart-override.d.ts +2 -0
- package/dist/scripts/smart-override.js +1360 -0
- package/dist/scripts/sync-configs.d.ts +27 -0
- package/dist/scripts/sync-configs.js +248 -0
- package/dist/scripts/test-biome-parse.d.ts +5 -0
- package/dist/scripts/test-biome-parse.js +84 -0
- package/dist/scripts/ultracite-setup.d.ts +4 -0
- package/dist/scripts/ultracite-setup.js +310 -0
- package/dist/scripts/update-all-init-scripts.d.ts +2 -0
- package/dist/scripts/update-all-init-scripts.js +52 -0
- package/dist/scripts/update-biome-schema.d.ts +15 -0
- package/dist/scripts/update-biome-schema.js +124 -0
- package/dist/src/AutoCoreFacade.d.ts +145 -0
- package/dist/src/AutoCoreFacade.js +217 -0
- package/dist/src/api/ApiActions.d.ts +297 -0
- package/dist/src/api/ApiActions.js +1905 -0
- package/dist/src/api/Certificate.d.ts +60 -0
- package/dist/src/api/Certificate.js +79 -0
- package/dist/src/api/JsonResponse.d.ts +116 -0
- package/dist/src/api/JsonResponse.js +206 -0
- package/dist/src/appium/DeviceFarmViewer.d.ts +79 -0
- package/dist/src/appium/DeviceFarmViewer.js +1083 -0
- package/dist/src/appium/MobileActions.d.ts +347 -0
- package/dist/src/appium/MobileActions.js +1632 -0
- package/dist/src/appium/MobileConnection.d.ts +160 -0
- package/dist/src/appium/MobileConnection.js +772 -0
- package/dist/src/config/envLoader.d.ts +123 -0
- package/dist/src/config/envLoader.js +361 -0
- package/dist/src/config/jest-safe-setup.d.ts +19 -0
- package/dist/src/config/jest-safe-setup.js +369 -0
- package/dist/src/config/timeouts.d.ts +32 -0
- package/dist/src/config/timeouts.js +38 -0
- package/dist/src/desktop/DesktopActions.d.ts +46 -0
- package/dist/src/desktop/DesktopActions.js +398 -0
- package/dist/src/desktop/DesktopConnection.d.ts +32 -0
- package/dist/src/desktop/DesktopConnection.js +84 -0
- package/dist/src/domain/entities/TestExecution.d.ts +117 -0
- package/dist/src/domain/entities/TestExecution.js +150 -0
- package/dist/src/domain/entities/TestReport.d.ts +114 -0
- package/dist/src/domain/entities/TestReport.js +179 -0
- package/dist/src/domain/repositories/ITestRepository.d.ts +196 -0
- package/dist/src/domain/repositories/ITestRepository.js +14 -0
- package/dist/src/domain/schemas/ValidationSchemas.d.ts +159 -0
- package/dist/src/domain/schemas/ValidationSchemas.js +181 -0
- package/dist/src/functions/errors/BaseError.d.ts +78 -0
- package/dist/src/functions/errors/BaseError.js +245 -0
- package/dist/src/functions/errors/ConfigurationError.d.ts +16 -0
- package/dist/src/functions/errors/ConfigurationError.js +48 -0
- package/dist/src/functions/errors/ErrorCatalog.d.ts +148 -0
- package/dist/src/functions/errors/ErrorCatalog.js +157 -0
- package/dist/src/functions/errors/GlobalErrorHandler.d.ts +101 -0
- package/dist/src/functions/errors/GlobalErrorHandler.js +281 -0
- package/dist/src/functions/errors/IntegrationError.d.ts +17 -0
- package/dist/src/functions/errors/IntegrationError.js +51 -0
- package/dist/src/functions/errors/SecurityError.d.ts +14 -0
- package/dist/src/functions/errors/SecurityError.js +42 -0
- package/dist/src/functions/errors/SystemError.d.ts +12 -0
- package/dist/src/functions/errors/SystemError.js +36 -0
- package/dist/src/functions/errors/ValidationError.d.ts +14 -0
- package/dist/src/functions/errors/ValidationError.js +61 -0
- package/dist/src/functions/errors/index.d.ts +12 -0
- package/dist/src/functions/errors/index.js +13 -0
- package/dist/src/global-setup.d.ts +1 -0
- package/dist/src/global-setup.js +1037 -0
- package/dist/src/helpers/BancoActions.d.ts +188 -0
- package/dist/src/helpers/BancoActions.js +581 -0
- package/dist/src/helpers/EnviromentHelper.d.ts +17 -0
- package/dist/src/helpers/EnviromentHelper.js +66 -0
- package/dist/src/helpers/ParallelExecutionHelper.d.ts +183 -0
- package/dist/src/helpers/ParallelExecutionHelper.js +375 -0
- package/dist/src/helpers/SyncSignal.d.ts +15 -0
- package/dist/src/helpers/SyncSignal.js +44 -0
- package/dist/src/hubdocs/CategoryDetector.d.ts +83 -0
- package/dist/src/hubdocs/CategoryDetector.js +401 -0
- package/dist/src/hubdocs/DirectStatementInterceptor.d.ts +54 -0
- package/dist/src/hubdocs/DirectStatementInterceptor.js +243 -0
- package/dist/src/hubdocs/ExecutionTracker.d.ts +107 -0
- package/dist/src/hubdocs/ExecutionTracker.js +702 -0
- package/dist/src/hubdocs/HubDocs.d.ts +395 -0
- package/dist/src/hubdocs/HubDocs.js +3586 -0
- package/dist/src/hubdocs/StatementMethodFilter.d.ts +71 -0
- package/dist/src/hubdocs/StatementMethodFilter.js +618 -0
- package/dist/src/hubdocs/StatementTracker.d.ts +417 -0
- package/dist/src/hubdocs/StatementTracker.js +2419 -0
- package/dist/src/hubdocs/SwaggerGenerator.d.ts +59 -0
- package/dist/src/hubdocs/SwaggerGenerator.js +405 -0
- package/dist/src/hubdocs/index.d.ts +9 -0
- package/dist/src/hubdocs/index.js +9 -0
- package/dist/src/hubdocs/types.d.ts +114 -0
- package/dist/src/hubdocs/types.js +5 -0
- package/dist/src/infrastructure/DependencyContainer.d.ts +142 -0
- package/dist/src/infrastructure/DependencyContainer.js +250 -0
- package/dist/src/infrastructure/adapters/AppiumAdapter.d.ts +168 -0
- package/dist/src/infrastructure/adapters/AppiumAdapter.js +468 -0
- package/dist/src/infrastructure/adapters/OracleAdapter.d.ts +150 -0
- package/dist/src/infrastructure/adapters/OracleAdapter.js +388 -0
- package/dist/src/infrastructure/adapters/PlaywrightAdapter.d.ts +192 -0
- package/dist/src/infrastructure/adapters/PlaywrightAdapter.js +382 -0
- package/dist/src/infrastructure/adapters/SSHAdapter.d.ts +141 -0
- package/dist/src/infrastructure/adapters/SSHAdapter.js +428 -0
- package/dist/src/interfaces.d.ts +501 -0
- package/dist/src/interfaces.js +25 -0
- package/dist/src/internal/fakes/__fake-actions__.d.ts +17 -0
- package/dist/src/internal/fakes/__fake-actions__.js +21 -0
- package/dist/src/internal/fakes/__forbidden__.d.ts +10 -0
- package/dist/src/internal/fakes/__forbidden__.js +18 -0
- package/dist/src/internal/fakes/__honeypot__.d.ts +15 -0
- package/dist/src/internal/fakes/__honeypot__.js +24 -0
- package/dist/src/octane/OctaneReporter.d.ts +13 -0
- package/dist/src/octane/OctaneReporter.js +61 -0
- package/dist/src/playwright/CryptoActions.d.ts +20 -0
- package/dist/src/playwright/CryptoActions.js +75 -0
- package/dist/src/playwright/EnhancedWebActions.d.ts +7 -0
- package/dist/src/playwright/EnhancedWebActions.js +65 -0
- package/dist/src/playwright/WebActions.d.ts +1599 -0
- package/dist/src/playwright/WebActions.js +11788 -0
- package/dist/src/playwright/actions/ActionTimeline.d.ts +36 -0
- package/dist/src/playwright/actions/ActionTimeline.js +101 -0
- package/dist/src/playwright/actions/RecoveryQueue.d.ts +82 -0
- package/dist/src/playwright/actions/RecoveryQueue.js +130 -0
- package/dist/src/playwright/actions/SelectorCache.d.ts +53 -0
- package/dist/src/playwright/actions/SelectorCache.js +96 -0
- package/dist/src/playwright/actions/index.d.ts +13 -0
- package/dist/src/playwright/actions/index.js +14 -0
- package/dist/src/playwright/actions/types.d.ts +147 -0
- package/dist/src/playwright/actions/types.js +5 -0
- package/dist/src/playwright/fixtures.d.ts +112 -0
- package/dist/src/playwright/fixtures.js +718 -0
- package/dist/src/playwright/network-logs-reporter.d.ts +7 -0
- package/dist/src/playwright/network-logs-reporter.js +66 -0
- package/dist/src/playwright/registerRecoveryWrappers.d.ts +1 -0
- package/dist/src/playwright/registerRecoveryWrappers.js +54 -0
- package/dist/src/security/BuildSecurity.d.ts +12 -0
- package/dist/src/security/BuildSecurity.js +138 -0
- package/dist/src/security/EulaProtection.d.ts +70 -0
- package/dist/src/security/EulaProtection.js +155 -0
- package/dist/src/security/HoneypotManager.d.ts +46 -0
- package/dist/src/security/HoneypotManager.js +234 -0
- package/dist/src/security/KeysManager.d.ts +36 -0
- package/dist/src/security/KeysManager.js +158 -0
- package/dist/src/security/ProofOfWorkIntegration.d.ts +64 -0
- package/dist/src/security/ProofOfWorkIntegration.js +206 -0
- package/dist/src/security/SecurityValidation.d.ts +21 -0
- package/dist/src/security/SecurityValidation.js +163 -0
- package/dist/src/security/SourceMapProtection.d.ts +55 -0
- package/dist/src/security/SourceMapProtection.js +220 -0
- package/dist/src/security/protector.d.ts +1 -0
- package/dist/src/security/protector.js +97 -0
- package/dist/src/ssh/SSHActions.d.ts +262 -0
- package/dist/src/ssh/SSHActions.js +790 -0
- package/dist/src/ssh/SSHClient.d.ts +99 -0
- package/dist/src/ssh/SSHClient.js +409 -0
- package/dist/src/statements/BaseStatement.d.ts +38 -0
- package/dist/src/statements/BaseStatement.js +78 -0
- package/dist/src/testContext/AuthStateManager.d.ts +93 -0
- package/dist/src/testContext/AuthStateManager.js +256 -0
- package/dist/src/testContext/CoverageManager.d.ts +198 -0
- package/dist/src/testContext/CoverageManager.js +917 -0
- package/dist/src/testContext/TestAnnotations.d.ts +476 -0
- package/dist/src/testContext/TestAnnotations.js +2647 -0
- package/dist/src/testContext/TestContext.d.ts +138 -0
- package/dist/src/testContext/TestContext.js +369 -0
- package/dist/src/testContext/UnifiedHtmlGenerator.d.ts +7 -0
- package/dist/src/testContext/UnifiedHtmlGenerator.js +264 -0
- package/dist/src/testContext/UnifiedReportManager.d.ts +211 -0
- package/dist/src/testContext/UnifiedReportManager.js +1206 -0
- package/dist/src/testhub/DynamicConfigManager.d.ts +121 -0
- package/dist/src/testhub/DynamicConfigManager.js +320 -0
- package/dist/src/testhub/SystemsManager.d.ts +119 -0
- package/dist/src/testhub/SystemsManager.js +365 -0
- package/dist/src/testhub/TestHubClient.d.ts +335 -0
- package/dist/src/testhub/TestHubClient.js +1215 -0
- package/dist/src/testhub/TestHubReporter.d.ts +62 -0
- package/dist/src/testhub/TestHubReporter.js +576 -0
- package/dist/src/testhub/TestHubVars.d.ts +116 -0
- package/dist/src/testhub/TestHubVars.js +273 -0
- package/dist/src/utils/ActionInterceptor.d.ts +59 -0
- package/dist/src/utils/ActionInterceptor.js +741 -0
- package/dist/src/utils/ArtifactsCompressor.d.ts +43 -0
- package/dist/src/utils/ArtifactsCompressor.js +181 -0
- package/dist/src/utils/AutoLogsFinal.d.ts +47 -0
- package/dist/src/utils/AutoLogsFinal.js +148 -0
- package/dist/src/utils/CodeGenSession.d.ts +114 -0
- package/dist/src/utils/CodeGenSession.js +264 -0
- package/dist/src/utils/ConfigLogger.d.ts +133 -0
- package/dist/src/utils/ConfigLogger.js +611 -0
- package/dist/src/utils/CustomReporter.d.ts +22 -0
- package/dist/src/utils/CustomReporter.js +352 -0
- package/dist/src/utils/DataStore.d.ts +171 -0
- package/dist/src/utils/DataStore.js +484 -0
- package/dist/src/utils/DatabaseInterceptor.d.ts +19 -0
- package/dist/src/utils/DatabaseInterceptor.js +295 -0
- package/dist/src/utils/DateHelper.d.ts +16 -0
- package/dist/src/utils/DateHelper.js +120 -0
- package/dist/src/utils/DateValidator.d.ts +4 -0
- package/dist/src/utils/DateValidator.js +51 -0
- package/dist/src/utils/DocumentGenerator.d.ts +35 -0
- package/dist/src/utils/DocumentGenerator.js +129 -0
- package/dist/src/utils/EvidenceCapture.d.ts +90 -0
- package/dist/src/utils/EvidenceCapture.js +600 -0
- package/dist/src/utils/EvidenceReportGenerator.d.ts +70 -0
- package/dist/src/utils/EvidenceReportGenerator.js +799 -0
- package/dist/src/utils/FrameManagementUtil.d.ts +42 -0
- package/dist/src/utils/FrameManagementUtil.js +75 -0
- package/dist/src/utils/GlobalStatementsInterceptor.d.ts +1 -0
- package/dist/src/utils/GlobalStatementsInterceptor.js +1 -0
- package/dist/src/utils/HTMLTemplate.d.ts +1 -0
- package/dist/src/utils/HTMLTemplate.js +1034 -0
- package/dist/src/utils/InterceptacaoMagica.d.ts +23 -0
- package/dist/src/utils/InterceptacaoMagica.js +365 -0
- package/dist/src/utils/LogSanitizer.d.ts +35 -0
- package/dist/src/utils/LogSanitizer.js +110 -0
- package/dist/src/utils/Logger.d.ts +65 -0
- package/dist/src/utils/Logger.js +284 -0
- package/dist/src/utils/McpLocalClient.d.ts +141 -0
- package/dist/src/utils/McpLocalClient.js +871 -0
- package/dist/src/utils/PDFEvidenceGenerator.d.ts +20 -0
- package/dist/src/utils/PDFEvidenceGenerator.js +156 -0
- package/dist/src/utils/SpecFileAnalyzer.d.ts +35 -0
- package/dist/src/utils/SpecFileAnalyzer.js +209 -0
- package/dist/src/utils/StatementInterceptor.d.ts +18 -0
- package/dist/src/utils/StatementInterceptor.js +87 -0
- package/dist/src/utils/StatementLogger.d.ts +33 -0
- package/dist/src/utils/StatementLogger.js +113 -0
- package/dist/src/utils/StatementsInterceptor.d.ts +1 -0
- package/dist/src/utils/StatementsInterceptor.js +1 -0
- package/dist/src/utils/TeamsFlushHook.d.ts +17 -0
- package/dist/src/utils/TeamsFlushHook.js +168 -0
- package/dist/src/utils/TerminalLogCapture.d.ts +158 -0
- package/dist/src/utils/TerminalLogCapture.js +531 -0
- package/dist/src/utils/TestMethodLogger.d.ts +70 -0
- package/dist/src/utils/TestMethodLogger.js +95 -0
- package/dist/src/utils/UnifiedTeardown.d.ts +4 -0
- package/dist/src/utils/UnifiedTeardown.js +400 -0
- package/dist/src/utils/XPathCatalog.d.ts +152 -0
- package/dist/src/utils/XPathCatalog.js +350 -0
- package/dist/src/utils/generators.d.ts +90 -0
- package/dist/src/utils/generators.js +167 -0
- package/dist/src/utils/testRecovery/ResilientPlaywright.d.ts +152 -0
- package/dist/src/utils/testRecovery/ResilientPlaywright.js +715 -0
- package/dist/src/utils/testRecovery/TestRecoveryClient.d.ts +801 -0
- package/dist/src/utils/testRecovery/TestRecoveryClient.js +1415 -0
- package/dist/src/utils/testRecovery/autoFixCode.d.ts +65 -0
- package/dist/src/utils/testRecovery/autoFixCode.js +32 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +59 -0
- package/dist/wdio.conf.d.ts +1 -0
- package/dist/wdio.conf.js +420 -0
- package/package.json +137 -0
- package/protect-loader.mjs +643 -0
- package/scripts/consumer-postinstall.ts +975 -0
- package/scripts/generate-index.ts +343 -0
- package/scripts/init-api.ts +613 -0
- package/scripts/init-banco.ts +437 -0
- package/scripts/init-frontend.ts +727 -0
- package/scripts/init-mobile.ts +558 -0
- package/scripts/init-scenarios.ts +925 -0
- package/scripts/init-ssh.ts +734 -0
- package/scripts/package-versions.ts +978 -0
- package/scripts/postinstall.ts +605 -0
- package/scripts/smart-override.ts +1675 -0
- package/scripts/sync-configs.ts +302 -0
- package/scripts/ultracite-setup.ts +370 -0
- package/src/types/globals.d.ts +48 -0
- package/tsconfig.json +29 -0
- package/types/autocore-sync-signal.d.ts +10 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GlobalErrorHandler: Sistema global de captura e tratamento de erros
|
|
3
|
+
* Gerencia erros não capturados e fornece logging e observabilidade
|
|
4
|
+
*/
|
|
5
|
+
import { BaseError } from './BaseError.js';
|
|
6
|
+
import { IntegrationError } from './IntegrationError.js';
|
|
7
|
+
import { SecurityError } from './SecurityError.js';
|
|
8
|
+
import { SystemError } from './SystemError.js';
|
|
9
|
+
import { Logger } from '../../utils/Logger.js';
|
|
10
|
+
export class GlobalErrorHandler {
|
|
11
|
+
static instance;
|
|
12
|
+
config;
|
|
13
|
+
errors = [];
|
|
14
|
+
metrics;
|
|
15
|
+
originalConsoleError;
|
|
16
|
+
originalProcessListeners = {};
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
this.config = {
|
|
19
|
+
enableConsoleLogging: true,
|
|
20
|
+
enableFileLogging: false,
|
|
21
|
+
maxErrorsInMemory: 100,
|
|
22
|
+
enableStackTrace: true,
|
|
23
|
+
enableUserFriendlyMessages: true,
|
|
24
|
+
enableObservability: false,
|
|
25
|
+
...config,
|
|
26
|
+
};
|
|
27
|
+
this.metrics = {
|
|
28
|
+
totalErrors: 0,
|
|
29
|
+
errorsByCategory: {},
|
|
30
|
+
errorsBySeverity: {},
|
|
31
|
+
recentErrors: [],
|
|
32
|
+
startTime: Date.now(),
|
|
33
|
+
};
|
|
34
|
+
this.originalConsoleError = console.error;
|
|
35
|
+
this.setupGlobalHandlers();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Obtém instância singleton do GlobalErrorHandler
|
|
39
|
+
*/
|
|
40
|
+
static getInstance(config) {
|
|
41
|
+
if (!GlobalErrorHandler.instance) {
|
|
42
|
+
GlobalErrorHandler.instance = new GlobalErrorHandler(config);
|
|
43
|
+
}
|
|
44
|
+
return GlobalErrorHandler.instance;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configura handlers globais para captura de erros
|
|
48
|
+
*/
|
|
49
|
+
setupGlobalHandlers() {
|
|
50
|
+
// Capturar erros não tratados
|
|
51
|
+
process.on('uncaughtException', (error) => {
|
|
52
|
+
this.handleUncaughtError(error, 'uncaughtException');
|
|
53
|
+
});
|
|
54
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
55
|
+
this.handleUnhandledRejection(reason, promise);
|
|
56
|
+
});
|
|
57
|
+
// Interceptar console.error para capturar logs de erro
|
|
58
|
+
console.error = (...args) => {
|
|
59
|
+
this.handleConsoleError(args);
|
|
60
|
+
this.originalConsoleError.apply(console, args);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Manuseia erro principal do sistema
|
|
65
|
+
*/
|
|
66
|
+
handleError(error, context) {
|
|
67
|
+
let processedError;
|
|
68
|
+
if (error instanceof BaseError) {
|
|
69
|
+
processedError = error;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Converter erro genérico para BaseError
|
|
73
|
+
processedError = this.convertToBaseError(error, context);
|
|
74
|
+
}
|
|
75
|
+
// Adicionar contexto adicional se fornecido
|
|
76
|
+
if (context) {
|
|
77
|
+
processedError.context.metadata = {
|
|
78
|
+
...processedError.context.metadata,
|
|
79
|
+
...context,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
this.logError(processedError);
|
|
83
|
+
this.updateMetrics(processedError);
|
|
84
|
+
this.storeError(processedError);
|
|
85
|
+
this.sendToObservability(processedError);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Manuseia erros não capturados
|
|
89
|
+
*/
|
|
90
|
+
handleUncaughtError(error, type) {
|
|
91
|
+
const baseError = new SecurityError('SYS_UNCAUGHT_EXCEPTION', `Uncaught exception (${type}): ${error.message}`, 'Erro não tratado detectado no sistema.', error, { metadata: { type, timestamp: Date.now() } });
|
|
92
|
+
this.handleError(baseError);
|
|
93
|
+
// Em ambiente de produção, evitar crash
|
|
94
|
+
if (process.env.NODE_ENV === 'production') {
|
|
95
|
+
Logger.error('💥 Sistema em modo degradado devido a erro crítico');
|
|
96
|
+
process.env.AUTOCORE_DEGRADED_MODE = 'true';
|
|
97
|
+
process.env.AUTOCORE_DEGRADED_REASON = 'uncaught_exception';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Manuseia rejeições não tratadas
|
|
102
|
+
*/
|
|
103
|
+
handleUnhandledRejection(reason, promise) {
|
|
104
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
105
|
+
const baseError = new IntegrationError('SYS_UNHANDLED_REJECTION', `Unhandled promise rejection: ${error.message}`, 'Promise rejeitada não tratada.', error, { metadata: { promise: promise.toString(), timestamp: Date.now() } });
|
|
106
|
+
this.handleError(baseError);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Manuseia logs de erro do console
|
|
110
|
+
*/
|
|
111
|
+
handleConsoleError(args) {
|
|
112
|
+
const message = args
|
|
113
|
+
.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg)))
|
|
114
|
+
.join(' ');
|
|
115
|
+
if (message.includes('AutoCore') || message.includes('⚠️')) {
|
|
116
|
+
// Este é provavelmente um erro do nosso sistema
|
|
117
|
+
const error = SystemError.consoleError(message);
|
|
118
|
+
this.storeError(error);
|
|
119
|
+
this.updateMetrics(error);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Converte erro genérico para BaseError
|
|
124
|
+
*/
|
|
125
|
+
convertToBaseError(error, context) {
|
|
126
|
+
// Tentar determinar tipo de erro baseado na mensagem
|
|
127
|
+
if (error.message.includes('ECONNREFUSED') ||
|
|
128
|
+
error.message.includes('network')) {
|
|
129
|
+
return IntegrationError.networkError('unknown', error, context);
|
|
130
|
+
}
|
|
131
|
+
if (error.message.includes('ENOENT') || error.message.includes('file')) {
|
|
132
|
+
return IntegrationError.fileSystemError('access', 'unknown', error, context);
|
|
133
|
+
}
|
|
134
|
+
if (error.message.includes('timeout')) {
|
|
135
|
+
return IntegrationError.timeoutError('unknown', 30_000, context);
|
|
136
|
+
}
|
|
137
|
+
// Erro genérico
|
|
138
|
+
return SystemError.genericError(error.message, error, context);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Registra erro nos logs
|
|
142
|
+
*/
|
|
143
|
+
logError(error) {
|
|
144
|
+
if (this.config.enableConsoleLogging) {
|
|
145
|
+
if (this.config.enableUserFriendlyMessages) {
|
|
146
|
+
console.error(error.getUserFriendlyMessage());
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.error(`[${error.severity.toUpperCase()}] ${error.code}: ${error.message}`);
|
|
150
|
+
}
|
|
151
|
+
if (this.config.enableStackTrace && error.stack) {
|
|
152
|
+
console.error(error.stack);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (this.config.enableFileLogging && this.config.logFilePath) {
|
|
156
|
+
this.writeToLogFile(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Escreve erro em arquivo de log
|
|
161
|
+
*/
|
|
162
|
+
async writeToLogFile(error) {
|
|
163
|
+
try {
|
|
164
|
+
const fs = await import('node:fs/promises');
|
|
165
|
+
const logEntry = `${new Date().toISOString()} - ${error.getTechnicalReport()}\n\n`;
|
|
166
|
+
await fs.appendFile(this.config.logFilePath, logEntry);
|
|
167
|
+
}
|
|
168
|
+
catch (writeError) {
|
|
169
|
+
Logger.error('Falha ao escrever no arquivo de log', writeError);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Atualiza métricas de erro
|
|
174
|
+
*/
|
|
175
|
+
updateMetrics(error) {
|
|
176
|
+
this.metrics.totalErrors++;
|
|
177
|
+
this.metrics.errorsByCategory[error.category] =
|
|
178
|
+
(this.metrics.errorsByCategory[error.category] || 0) + 1;
|
|
179
|
+
this.metrics.errorsBySeverity[error.severity] =
|
|
180
|
+
(this.metrics.errorsBySeverity[error.severity] || 0) + 1;
|
|
181
|
+
this.metrics.recentErrors.unshift(error);
|
|
182
|
+
if (this.metrics.recentErrors.length > 10) {
|
|
183
|
+
this.metrics.recentErrors.pop();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Armazena erro na memória
|
|
188
|
+
*/
|
|
189
|
+
storeError(error) {
|
|
190
|
+
this.errors.unshift(error);
|
|
191
|
+
// Limitar número de erros em memória
|
|
192
|
+
if (this.errors.length > this.config.maxErrorsInMemory) {
|
|
193
|
+
this.errors = this.errors.slice(0, this.config.maxErrorsInMemory);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Envia erro para sistema de observabilidade
|
|
198
|
+
*/
|
|
199
|
+
async sendToObservability(error) {
|
|
200
|
+
if (!(this.config.enableObservability && this.config.observabilityEndpoint)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
// Implementar envio para Axiom, Jaeger, etc.
|
|
205
|
+
const payload = {
|
|
206
|
+
timestamp: error.timestamp,
|
|
207
|
+
level: error.severity,
|
|
208
|
+
message: error.message,
|
|
209
|
+
error: error.toJSON(),
|
|
210
|
+
context: error.context,
|
|
211
|
+
};
|
|
212
|
+
// Aqui seria implementado o envio real
|
|
213
|
+
console.debug('Sending error to observability:', payload);
|
|
214
|
+
}
|
|
215
|
+
catch (observabilityError) {
|
|
216
|
+
Logger.error('Falha ao enviar erro para observabilidade', observabilityError);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Obtém métricas atuais
|
|
221
|
+
*/
|
|
222
|
+
getMetrics() {
|
|
223
|
+
return { ...this.metrics };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Obtém erros recentes
|
|
227
|
+
*/
|
|
228
|
+
getRecentErrors(limit = 10) {
|
|
229
|
+
return this.errors.slice(0, limit);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Gera relatório de status
|
|
233
|
+
*/
|
|
234
|
+
generateStatusReport() {
|
|
235
|
+
const uptime = Date.now() - this.metrics.startTime;
|
|
236
|
+
const uptimeHours = Math.floor(uptime / (1000 * 60 * 60));
|
|
237
|
+
const uptimeMinutes = Math.floor((uptime % (1000 * 60 * 60)) / (1000 * 60));
|
|
238
|
+
const report = [
|
|
239
|
+
'=== RELATÓRIO DE STATUS AUTOCORE ===',
|
|
240
|
+
`Uptime: ${uptimeHours}h ${uptimeMinutes}m`,
|
|
241
|
+
`Total de Erros: ${this.metrics.totalErrors}`,
|
|
242
|
+
'',
|
|
243
|
+
'Erros por Categoria:',
|
|
244
|
+
...Object.entries(this.metrics.errorsByCategory).map(([cat, count]) => ` ${cat}: ${count}`),
|
|
245
|
+
'',
|
|
246
|
+
'Erros por Severidade:',
|
|
247
|
+
...Object.entries(this.metrics.errorsBySeverity).map(([sev, count]) => ` ${sev}: ${count}`),
|
|
248
|
+
'',
|
|
249
|
+
`Erros Recentes (${this.metrics.recentErrors.length}):`,
|
|
250
|
+
...this.metrics.recentErrors
|
|
251
|
+
.slice(0, 5)
|
|
252
|
+
.map((err) => ` ${err.code}: ${err.userMessage}`),
|
|
253
|
+
];
|
|
254
|
+
return report.join('\n');
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Limpa erros armazenados
|
|
258
|
+
*/
|
|
259
|
+
clearErrors() {
|
|
260
|
+
this.errors = [];
|
|
261
|
+
this.metrics.recentErrors = [];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Desativa handlers globais
|
|
265
|
+
*/
|
|
266
|
+
dispose() {
|
|
267
|
+
console.error = this.originalConsoleError;
|
|
268
|
+
// Remover listeners se possível
|
|
269
|
+
// Note: não é possível remover completamente os listeners de uncaughtException
|
|
270
|
+
// mas podemos restaurar comportamentos originais
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// Inicializar handler global automaticamente
|
|
274
|
+
export const globalErrorHandler = GlobalErrorHandler.getInstance({
|
|
275
|
+
enableConsoleLogging: process.env.NODE_ENV !== 'test',
|
|
276
|
+
enableFileLogging: process.env.AUTOCORE_LOG_FILE === 'true',
|
|
277
|
+
logFilePath: process.env.AUTOCORE_LOG_PATH || './autocore-errors.log',
|
|
278
|
+
enableObservability: process.env.AUTOCORE_OBSERVABILITY === 'true',
|
|
279
|
+
observabilityEndpoint: process.env.AUTOCORE_OBSERVABILITY_ENDPOINT,
|
|
280
|
+
});
|
|
281
|
+
export default GlobalErrorHandler;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IntegrationError: Erros de integração com sistemas externos
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError, type ErrorContext } from './BaseError.js';
|
|
5
|
+
export declare class IntegrationError extends BaseError {
|
|
6
|
+
constructor(code: string, message: string, userMessage: string, originalError?: Error, context?: Partial<ErrorContext>);
|
|
7
|
+
static browserLaunchFailed(browserType: string, error: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
8
|
+
static databaseConnectionFailed(database: string, error: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
9
|
+
static apiRequestFailed(url: string, statusCode: number, responseText: string, context?: Partial<ErrorContext>): IntegrationError;
|
|
10
|
+
static sshConnectionFailed(host: string, error: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
11
|
+
static fileSystemError(operation: string, path: string, error: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
12
|
+
static mobileDeviceConnectionFailed(deviceId: string, error: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
13
|
+
static timeoutError(operation: string, timeoutMs: number, context?: Partial<ErrorContext>): IntegrationError;
|
|
14
|
+
static networkError(host: string, error: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
15
|
+
static webOperationFailed(operation: string, details: string, error?: Error, context?: Partial<ErrorContext>): IntegrationError;
|
|
16
|
+
}
|
|
17
|
+
export default IntegrationError;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IntegrationError: Erros de integração com sistemas externos
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError } from './BaseError.js';
|
|
5
|
+
export class IntegrationError extends BaseError {
|
|
6
|
+
constructor(code, message, userMessage, originalError, context) {
|
|
7
|
+
const details = {
|
|
8
|
+
code,
|
|
9
|
+
message,
|
|
10
|
+
userMessage,
|
|
11
|
+
category: 'integration',
|
|
12
|
+
severity: 'high',
|
|
13
|
+
recoverable: true,
|
|
14
|
+
suggestions: [
|
|
15
|
+
'Verifique a conectividade com o sistema externo',
|
|
16
|
+
'Confirme se as credenciais estão corretas',
|
|
17
|
+
'Tente novamente após alguns minutos',
|
|
18
|
+
],
|
|
19
|
+
documentation: 'https://docs.autocore.rbqa/integration',
|
|
20
|
+
};
|
|
21
|
+
super(details, originalError, context);
|
|
22
|
+
}
|
|
23
|
+
static browserLaunchFailed(browserType, error, context) {
|
|
24
|
+
return new IntegrationError('INT_BROWSER_LAUNCH_FAILED', `Failed to launch ${browserType} browser: ${error.message}`, `Falha ao iniciar navegador ${browserType}. Verifique se está instalado corretamente.`, error, { ...context, metadata: { browserType } });
|
|
25
|
+
}
|
|
26
|
+
static databaseConnectionFailed(database, error, context) {
|
|
27
|
+
return new IntegrationError('INT_DATABASE_CONNECTION_FAILED', `Database connection failed for ${database}: ${error.message}`, `Falha na conexão com o banco de dados ${database}.`, error, { ...context, metadata: { database } });
|
|
28
|
+
}
|
|
29
|
+
static apiRequestFailed(url, statusCode, responseText, context) {
|
|
30
|
+
return new IntegrationError('INT_API_REQUEST_FAILED', `API request failed: ${statusCode} - ${responseText}`, `Falha na requisição para ${url}. Código: ${statusCode}`, undefined, { ...context, metadata: { url, statusCode, responseText } });
|
|
31
|
+
}
|
|
32
|
+
static sshConnectionFailed(host, error, context) {
|
|
33
|
+
return new IntegrationError('INT_SSH_CONNECTION_FAILED', `SSH connection failed to ${host}: ${error.message}`, `Falha na conexão SSH com ${host}.`, error, { ...context, metadata: { host } });
|
|
34
|
+
}
|
|
35
|
+
static fileSystemError(operation, path, error, context) {
|
|
36
|
+
return new IntegrationError('INT_FILESYSTEM_ERROR', `File system error during ${operation} on ${path}: ${error.message}`, `Erro no sistema de arquivos ao ${operation} ${path}.`, error, { ...context, metadata: { operation, path } });
|
|
37
|
+
}
|
|
38
|
+
static mobileDeviceConnectionFailed(deviceId, error, context) {
|
|
39
|
+
return new IntegrationError('INT_MOBILE_DEVICE_CONNECTION_FAILED', `Failed to connect to mobile device ${deviceId}: ${error.message}`, `Falha na conexão com dispositivo móvel ${deviceId}.`, error, { ...context, metadata: { deviceId } });
|
|
40
|
+
}
|
|
41
|
+
static timeoutError(operation, timeoutMs, context) {
|
|
42
|
+
return new IntegrationError('INT_TIMEOUT_ERROR', `Operation '${operation}' timed out after ${timeoutMs}ms`, `Timeout na operação '${operation}' após ${timeoutMs}ms.`, undefined, { ...context, metadata: { operation, timeoutMs } });
|
|
43
|
+
}
|
|
44
|
+
static networkError(host, error, context) {
|
|
45
|
+
return new IntegrationError('INT_NETWORK_ERROR', `Network error connecting to ${host}: ${error.message}`, `Erro de rede ao conectar com ${host}.`, error, { ...context, metadata: { host } });
|
|
46
|
+
}
|
|
47
|
+
static webOperationFailed(operation, details, error, context) {
|
|
48
|
+
return new IntegrationError('INT_WEB_OPERATION_FAILED', `Web operation '${operation}' failed: ${details}`, `Falha na operação web '${operation}': ${details}`, error, { ...context, metadata: { operation, details } });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export default IntegrationError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SecurityError: Erros relacionados à segurança e proteção
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError, type ErrorContext } from './BaseError.js';
|
|
5
|
+
export declare class SecurityError extends BaseError {
|
|
6
|
+
constructor(code: string, message: string, userMessage: string, originalError?: Error, context?: Partial<ErrorContext>);
|
|
7
|
+
static honeypotTriggered(source: string, context?: Partial<ErrorContext>): SecurityError;
|
|
8
|
+
static integrityCheckFailed(file: string, context?: Partial<ErrorContext>): SecurityError;
|
|
9
|
+
static eulaNotAccepted(context?: Partial<ErrorContext>): SecurityError;
|
|
10
|
+
static proofOfWorkFailed(method: string, context?: Partial<ErrorContext>): SecurityError;
|
|
11
|
+
static unauthorizedAccess(resource: string, context?: Partial<ErrorContext>): SecurityError;
|
|
12
|
+
static keyGenerationFailed(reason: string, context?: Partial<ErrorContext>): SecurityError;
|
|
13
|
+
}
|
|
14
|
+
export default SecurityError;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SecurityError: Erros relacionados à segurança e proteção
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError } from './BaseError.js';
|
|
5
|
+
export class SecurityError extends BaseError {
|
|
6
|
+
constructor(code, message, userMessage, originalError, context) {
|
|
7
|
+
const details = {
|
|
8
|
+
code,
|
|
9
|
+
message,
|
|
10
|
+
userMessage,
|
|
11
|
+
category: 'security',
|
|
12
|
+
severity: 'high',
|
|
13
|
+
recoverable: false,
|
|
14
|
+
suggestions: [
|
|
15
|
+
'Verifique se o ambiente não está sendo monitorado por automação',
|
|
16
|
+
'Execute em modo degradado se necessário',
|
|
17
|
+
'Consulte a documentação de segurança',
|
|
18
|
+
],
|
|
19
|
+
documentation: 'https://docs.autocore.rbqa/security',
|
|
20
|
+
};
|
|
21
|
+
super(details, originalError, context);
|
|
22
|
+
}
|
|
23
|
+
static honeypotTriggered(source, context) {
|
|
24
|
+
return new SecurityError('SEC_HONEYPOT_TRIGGERED', `Honeypot triggered from source: ${source}`, 'Sistema de proteção ativado. Detecção de uso automatizado.', undefined, { ...context, metadata: { source } });
|
|
25
|
+
}
|
|
26
|
+
static integrityCheckFailed(file, context) {
|
|
27
|
+
return new SecurityError('SEC_INTEGRITY_FAILED', `Integrity check failed for file: ${file}`, `Arquivo ${file} pode ter sido modificado ou corrompido.`, undefined, { ...context, metadata: { file } });
|
|
28
|
+
}
|
|
29
|
+
static eulaNotAccepted(context) {
|
|
30
|
+
return new SecurityError('SEC_EULA_NOT_ACCEPTED', 'EULA not accepted', 'Termos de uso não aceitos. O sistema funcionará em modo degradado.', undefined, context);
|
|
31
|
+
}
|
|
32
|
+
static proofOfWorkFailed(method, context) {
|
|
33
|
+
return new SecurityError('SEC_POW_FAILED', `Proof of work failed for method: ${method}`, `Validação de proof-of-work falhou para ${method}. Possível automação detectada.`, undefined, { ...context, metadata: { method } });
|
|
34
|
+
}
|
|
35
|
+
static unauthorizedAccess(resource, context) {
|
|
36
|
+
return new SecurityError('SEC_UNAUTHORIZED_ACCESS', `Unauthorized access attempt to: ${resource}`, `Acesso não autorizado detectado para ${resource}.`, undefined, { ...context, metadata: { resource } });
|
|
37
|
+
}
|
|
38
|
+
static keyGenerationFailed(reason, context) {
|
|
39
|
+
return new SecurityError('SEC_KEY_GENERATION_FAILED', `Key generation failed: ${reason}`, 'Falha na geração de chaves de segurança.', undefined, { ...context, metadata: { reason } });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export default SecurityError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemError: Erros internos do sistema AutoCore
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError, type ErrorContext } from './BaseError.js';
|
|
5
|
+
export declare class SystemError extends BaseError {
|
|
6
|
+
constructor(code: string, message: string, userMessage: string, originalError?: Error, context?: Partial<ErrorContext>);
|
|
7
|
+
static consoleError(message: string, context?: Partial<ErrorContext>): SystemError;
|
|
8
|
+
static genericError(message: string, originalError?: Error, context?: Partial<ErrorContext>): SystemError;
|
|
9
|
+
static initializationError(component: string, error: Error, context?: Partial<ErrorContext>): SystemError;
|
|
10
|
+
static resourceExhausted(resource: string, limit: number, context?: Partial<ErrorContext>): SystemError;
|
|
11
|
+
}
|
|
12
|
+
export default SystemError;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemError: Erros internos do sistema AutoCore
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError } from './BaseError.js';
|
|
5
|
+
export class SystemError extends BaseError {
|
|
6
|
+
constructor(code, message, userMessage, originalError, context) {
|
|
7
|
+
const details = {
|
|
8
|
+
code,
|
|
9
|
+
message,
|
|
10
|
+
userMessage,
|
|
11
|
+
category: 'system',
|
|
12
|
+
severity: 'medium',
|
|
13
|
+
recoverable: true,
|
|
14
|
+
suggestions: [
|
|
15
|
+
'Reinicie a aplicação se o problema persistir',
|
|
16
|
+
'Verifique os logs para mais detalhes',
|
|
17
|
+
'Contate o suporte se necessário',
|
|
18
|
+
],
|
|
19
|
+
documentation: 'https://docs.autocore.rbqa/system',
|
|
20
|
+
};
|
|
21
|
+
super(details, originalError, context);
|
|
22
|
+
}
|
|
23
|
+
static consoleError(message, context) {
|
|
24
|
+
return new SystemError('SYS_CONSOLE_ERROR', `Console error: ${message}`, 'Erro detectado no console do sistema.', undefined, context);
|
|
25
|
+
}
|
|
26
|
+
static genericError(message, originalError, context) {
|
|
27
|
+
return new SystemError('SYS_GENERIC_ERROR', message, 'Erro inesperado no sistema.', originalError, context);
|
|
28
|
+
}
|
|
29
|
+
static initializationError(component, error, context) {
|
|
30
|
+
return new SystemError('SYS_INITIALIZATION_ERROR', `Failed to initialize ${component}: ${error.message}`, `Falha na inicialização do componente ${component}.`, error, { ...context, metadata: { component } });
|
|
31
|
+
}
|
|
32
|
+
static resourceExhausted(resource, limit, context) {
|
|
33
|
+
return new SystemError('SYS_RESOURCE_EXHAUSTED', `Resource ${resource} exhausted, limit: ${limit}`, `Recurso ${resource} esgotado. Limite: ${limit}`, undefined, { ...context, metadata: { resource, limit } });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export default SystemError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ValidationError: Erros de validação de parâmetros e configurações
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError, type ErrorContext } from './BaseError.js';
|
|
5
|
+
export declare class ValidationError extends BaseError {
|
|
6
|
+
constructor(code: string, message: string, userMessage: string, originalError?: Error, context?: Partial<ErrorContext>);
|
|
7
|
+
static invalidParameter(paramName: string, expectedType: string, actualValue: unknown, context?: Partial<ErrorContext>): ValidationError;
|
|
8
|
+
static missingRequiredParameter(paramName: string, context?: Partial<ErrorContext>): ValidationError;
|
|
9
|
+
static invalidConfiguration(configKey: string, reason: string, context?: Partial<ErrorContext>): ValidationError;
|
|
10
|
+
static invalidSelector(selector: string, context?: Partial<ErrorContext>): ValidationError;
|
|
11
|
+
static invalidUrl(url: string, reason: string, context?: Partial<ErrorContext>): ValidationError;
|
|
12
|
+
static valueOutOfRange(paramName: string, value: number, min?: number, max?: number, context?: Partial<ErrorContext>): ValidationError;
|
|
13
|
+
}
|
|
14
|
+
export default ValidationError;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ValidationError: Erros de validação de parâmetros e configurações
|
|
3
|
+
*/
|
|
4
|
+
import { BaseError } from './BaseError.js';
|
|
5
|
+
export class ValidationError extends BaseError {
|
|
6
|
+
constructor(code, message, userMessage, originalError, context) {
|
|
7
|
+
const details = {
|
|
8
|
+
code,
|
|
9
|
+
message,
|
|
10
|
+
userMessage,
|
|
11
|
+
category: 'validation',
|
|
12
|
+
severity: 'medium',
|
|
13
|
+
recoverable: true,
|
|
14
|
+
suggestions: [
|
|
15
|
+
'Verifique os parâmetros informados',
|
|
16
|
+
'Consulte a documentação da API',
|
|
17
|
+
'Valide a configuração do projeto',
|
|
18
|
+
],
|
|
19
|
+
documentation: 'https://docs.autocore.rbqa/validation',
|
|
20
|
+
};
|
|
21
|
+
super(details, originalError, context);
|
|
22
|
+
}
|
|
23
|
+
static invalidParameter(paramName, expectedType, actualValue, context) {
|
|
24
|
+
return new ValidationError('VAL_INVALID_PARAMETER', `Invalid parameter '${paramName}': expected ${expectedType}, got ${typeof actualValue}`, `Parâmetro '${paramName}' inválido. Esperado: ${expectedType}`, undefined, {
|
|
25
|
+
...context,
|
|
26
|
+
metadata: {
|
|
27
|
+
paramName,
|
|
28
|
+
expectedType,
|
|
29
|
+
actualType: typeof actualValue,
|
|
30
|
+
actualValue,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
static missingRequiredParameter(paramName, context) {
|
|
35
|
+
return new ValidationError('VAL_MISSING_PARAMETER', `Missing required parameter: ${paramName}`, `Parâmetro obrigatório '${paramName}' não informado.`, undefined, { ...context, metadata: { paramName } });
|
|
36
|
+
}
|
|
37
|
+
static invalidConfiguration(configKey, reason, context) {
|
|
38
|
+
return new ValidationError('VAL_INVALID_CONFIG', `Invalid configuration for '${configKey}': ${reason}`, `Configuração inválida para '${configKey}': ${reason}`, undefined, { ...context, metadata: { configKey, reason } });
|
|
39
|
+
}
|
|
40
|
+
static invalidSelector(selector, context) {
|
|
41
|
+
const error = new ValidationError('VAL_INVALID_SELECTOR', `Invalid selector: ${selector}`, `Seletor CSS/XPath inválido: ${selector}`, undefined, { ...context, metadata: { selector } });
|
|
42
|
+
error.suggestions.push('Verifique a sintaxe do seletor CSS ou XPath', 'Use ferramentas de desenvolvedor do navegador para testar', 'Consulte a documentação de seletores');
|
|
43
|
+
return error;
|
|
44
|
+
}
|
|
45
|
+
static invalidUrl(url, reason, context) {
|
|
46
|
+
const error = new ValidationError('VAL_INVALID_URL', `Invalid URL: ${url} - ${reason}`, `URL inválida: ${url}`, undefined, { ...context, metadata: { url, reason } });
|
|
47
|
+
error.suggestions.push('Verifique se a URL está correta', 'Inclua protocolo (http:// ou https://)', 'Verifique se o servidor está acessível');
|
|
48
|
+
return error;
|
|
49
|
+
}
|
|
50
|
+
static valueOutOfRange(paramName, value, min, max, context) {
|
|
51
|
+
const range = min !== undefined && max !== undefined
|
|
52
|
+
? `entre ${min} e ${max}`
|
|
53
|
+
: min !== undefined
|
|
54
|
+
? `maior ou igual a ${min}`
|
|
55
|
+
: max !== undefined
|
|
56
|
+
? `menor ou igual a ${max}`
|
|
57
|
+
: 'no intervalo permitido';
|
|
58
|
+
return new ValidationError('VAL_VALUE_OUT_OF_RANGE', `Value ${value} for parameter '${paramName}' is out of range`, `Valor ${value} para '${paramName}' deve estar ${range}.`, undefined, { ...context, metadata: { paramName, value, min, max } });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export default ValidationError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index de todas as classes de erro do AutoCore
|
|
3
|
+
* Facilita importação e uso das classes de erro
|
|
4
|
+
*/
|
|
5
|
+
export { BaseError, default as AutoCoreErrors, type ErrorContext, type ErrorDetails, } from './BaseError.js';
|
|
6
|
+
export { ConfigurationError } from './ConfigurationError.js';
|
|
7
|
+
export { type ErrorHandlerConfig, type ErrorMetrics, GlobalErrorHandler, globalErrorHandler, } from './GlobalErrorHandler.js';
|
|
8
|
+
export { IntegrationError } from './IntegrationError.js';
|
|
9
|
+
export { SecurityError } from './SecurityError.js';
|
|
10
|
+
export { SystemError } from './SystemError.js';
|
|
11
|
+
export { ValidationError } from './ValidationError.js';
|
|
12
|
+
export { ErrorCatalog, formatError, getErrorHint, type ErrorCode, type ErrorEntry, type ErrorSeverity, } from './ErrorCatalog.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index de todas as classes de erro do AutoCore
|
|
3
|
+
* Facilita importação e uso das classes de erro
|
|
4
|
+
*/
|
|
5
|
+
// Re-export default
|
|
6
|
+
export { BaseError, default as AutoCoreErrors, } from './BaseError.js';
|
|
7
|
+
export { ConfigurationError } from './ConfigurationError.js';
|
|
8
|
+
export { GlobalErrorHandler, globalErrorHandler, } from './GlobalErrorHandler.js';
|
|
9
|
+
export { IntegrationError } from './IntegrationError.js';
|
|
10
|
+
export { SecurityError } from './SecurityError.js';
|
|
11
|
+
export { SystemError } from './SystemError.js';
|
|
12
|
+
export { ValidationError } from './ValidationError.js';
|
|
13
|
+
export { ErrorCatalog, formatError, getErrorHint, } from './ErrorCatalog.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function globalSetup(): Promise<void>;
|