MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / applySourceMapsToStack

Function applySourceMapsToStack

webview-ui/src/utils/sourceMapUtils.ts:15–54  ·  view source on GitHub ↗
(stack: string)

Source from the content-addressed store, hash-verified

13 * Returns the original stack trace if source maps can't be applied
14 */
15export async function applySourceMapsToStack(stack: string): Promise<string> {
16 if (!stack) {
17 console.debug("applySourceMapsToStack: Empty stack trace provided")
18 return stack
19 }
20
21 console.debug("Original stack trace:", stack)
22
23 try {
24 // Create a temporary Error object with the provided stack
25 const tempError = new Error()
26 tempError.stack = stack
27
28 // Extract the error message (first line)
29 const errorMessage = stack.split("\n")[0]
30 console.debug("Error message:", errorMessage)
31
32 // Use StackTrace.js to get source mapped stack frames
33 const stackFrames = await StackTrace.fromError(tempError)
34 console.debug("StackTrace.js parsed frames:", stackFrames)
35
36 // Convert stack frames back to string format
37 const mappedFrames = stackFrames.map((frame: StackTrace.StackFrame) => {
38 const functionName = frame.functionName || "<anonymous>"
39 const fileName = frame.fileName || "unknown"
40 const lineNumber = frame.lineNumber || 0
41 const columnNumber = frame.columnNumber || 0
42
43 return ` at ${functionName} (${fileName}:${lineNumber}:${columnNumber})`
44 })
45
46 // Reconstruct the stack trace with the error message
47 const result = [errorMessage, ...mappedFrames].join("\n")
48 console.debug("Final mapped stack trace:", result)
49 return result
50 } catch (error) {
51 console.error("Error applying source maps with StackTrace.js:", error)
52 return stack // Return original stack on error
53 }
54}
55
56/**
57 * Apply source maps to a React component stack trace using StackTrace.js

Callers 2

Calls 2

debugMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected