(error: Error, componentStack?: string)
| 117 | * Enhance an Error object with source mapped stack trace and component stack |
| 118 | */ |
| 119 | export function enhanceErrorWithSourceMaps(error: Error, componentStack?: string): Promise<EnhancedError> { |
| 120 | console.debug("Enhancing error with source maps using StackTrace.js:", error) |
| 121 | |
| 122 | return new Promise<EnhancedError>((resolve) => { |
| 123 | if (!error.stack) { |
| 124 | console.debug("Error has no stack trace") |
| 125 | resolve(error as EnhancedError) |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | // Process both stacks in parallel |
| 130 | const stackPromise = applySourceMapsToStack(error.stack) |
| 131 | const componentStackPromise = componentStack |
| 132 | ? applySourceMapsToComponentStack(componentStack) |
| 133 | : Promise.resolve(undefined) |
| 134 | |
| 135 | Promise.all([stackPromise, componentStackPromise]) |
| 136 | .then(([sourceMappedStack, sourceMappedComponentStack]) => { |
| 137 | console.debug("Source mapped stacks applied successfully with StackTrace.js") |
| 138 | |
| 139 | // Extend the error object with the source mapped stack |
| 140 | Object.defineProperty(error, "sourceMappedStack", { |
| 141 | value: sourceMappedStack, |
| 142 | writable: true, |
| 143 | configurable: true, |
| 144 | }) |
| 145 | |
| 146 | // Add the source mapped component stack if available |
| 147 | if (sourceMappedComponentStack) { |
| 148 | Object.defineProperty(error, "sourceMappedComponentStack", { |
| 149 | value: sourceMappedComponentStack, |
| 150 | writable: true, |
| 151 | configurable: true, |
| 152 | }) |
| 153 | } |
| 154 | |
| 155 | resolve(error) |
| 156 | }) |
| 157 | .catch((mapError) => { |
| 158 | console.error("Error applying source maps with StackTrace.js:", mapError) |
| 159 | // If anything fails, just return the original error |
| 160 | resolve(error) |
| 161 | }) |
| 162 | }) |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Parse a stack trace string into structured stack frames |
no test coverage detected