UNPKG

@lucidlayer/babel-plugin-traceform

Version:

Babel plugin to inject data-traceform-id attributes into React components for Traceform

51 lines 2.43 kB
"use strict"; // SPDX-License-Identifier: BUSL-1.1 /** * Traceform Central Error Handling Utilities for Babel Plugin * Implements the TraceformError interface, error code scheme, and central handler. * See memory_docs/codeMap_root.md and components_index.yaml for documentation. * * Error Code Format: TF-BABEL-[ERRNO] (e.g., TF-BABEL-001) * All errors should use this structure and be routed through handleTraceformError. * I18N and telemetry hooks are stubbed for future implementation. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.handleTraceformError = handleTraceformError; exports.createTraceformError = createTraceformError; /** * Central error handler for all Traceform tools. * Logs, surfaces to UI/DevTools, and triggers telemetry/I18N hooks as needed. * * @param error - TraceformError object * @param context - Optional context (component, step, etc.) */ function handleTraceformError(error, context) { // Log error with code and context const ctx = context ? `[${context}]` : ''; // eslint-disable-next-line no-console console.error(`%c[${error.code}]${ctx} ${error.message}`, 'color: red; font-weight: bold;', error.details || ''); // TODO: Surface to UI/DevTools if available (e.g., postMessage, panel log) // TODO: Integrate with I18N system using error.i18nKey // TODO: Trigger telemetry event if error.telemetry is true // Example stub: if (error.telemetry) { // sendTelemetryEvent('errorEncountered', { code: error.code, ... }) } } /** * Utility to create a TraceformError with standard fields. * @param code - Error code (TF-BABEL-[ERRNO] for Babel Plugin) * @param message - User-facing or log message * @param details - Optional details (stack, context, etc.) * @param i18nKey - Optional I18N key * @param telemetry - Flag for telemetry reporting */ function createTraceformError(code, message, details, i18nKey, telemetry = true) { // Ensure the code starts with TF-BABEL- for Babel Plugin const formattedCode = code.startsWith('TF-BABEL-') ? code : `TF-BABEL-${code}`; return { code: formattedCode, message, details, i18nKey, telemetry }; } // Example usage (to be replaced in all babel plugin components): // throw createTraceformError('TF-BABEL-001', 'Transformation error occurred', { node: ... }); // handleTraceformError(error, 'BabelTransform'); //# sourceMappingURL=traceformError.js.map