1+ import { originalPositionFor , sourceContentFor } from '@jridgewell/trace-mapping' ;
2+ import type { StackFrameLite } from 'error-stack-parser-es/lite' ;
13import { type Accessor , createMemo } from 'solid-js' ;
24import getSourceMap from './get-source-map.js' ;
35
@@ -26,30 +28,38 @@ function getActualFileSource(path: string): string {
2628 return path ;
2729}
2830
29- export function createStackFrame ( stackframe : StackFrame , isCompiled : ( ) => boolean ) {
31+ export function createStackFrame ( stackframe : StackFrameLite , isCompiled : ( ) => boolean ) {
3032 const data = createMemo ( async ( ) => {
3133 const source = {
32- fileName : stackframe . fileName ,
33- line : stackframe . lineNumber ,
34- column : stackframe . columnNumber ,
35- functionName : stackframe . functionName ,
34+ fileName : stackframe . file ,
35+ line : stackframe . line ,
36+ column : stackframe . col ,
37+ functionName : stackframe . function ,
3638 } ;
3739 if ( ! source . fileName ) {
3840 return null ;
3941 }
40- const response = await fetch ( getActualFileSource ( source . fileName ) ) ;
41- if ( ! response . ok ) {
42+ // Sources can be unreachable — node internals, extension scripts,
43+ // files outside the dev server's allowlist. Treat any failure as
44+ // "no source" instead of throwing into the error boundary.
45+ try {
46+ const url = getActualFileSource ( source . fileName ) ;
47+ const response = await fetch ( url ) ;
48+ if ( ! response . ok ) {
49+ return null ;
50+ }
51+ const content = await response . text ( ) ;
52+ const sourceMap = await getSourceMap ( url , content ) ;
53+ return {
54+ source,
55+ content,
56+ sourceMap,
57+ isServer : isServerSource ( source . fileName ) ,
58+ } ;
59+ } catch ( error ) {
60+ console . warn ( '[solid dev toolbar] failed to load source for stack frame' , error ) ;
4261 return null ;
4362 }
44- const content = await response . text ( ) ;
45- const url = getActualFileSource ( source . fileName ) ;
46- const sourceMap = await getSourceMap ( url , content ) ;
47- return {
48- source,
49- content,
50- sourceMap,
51- isServer : isServerSource ( source . fileName ) ,
52- } ;
5363 } ) ;
5464
5565 const info = createMemo ( ( ) => {
@@ -61,9 +71,12 @@ export function createStackFrame(stackframe: StackFrame, isCompiled: () => boole
6171
6272 if ( ! isCompiled ( ) && source . line && source . column && sourceMap ) {
6373 if ( isServer ) {
64- const originalContent = sourceMap . sources . length
65- ? sourceMap . sourceContentFor ( sourceMap . sources [ 0 ] ! , true )
66- : null ;
74+ // The position is already original; only the original content needs
75+ // to be pulled out of the source map.
76+ const originalContent =
77+ sourceMap . sources . length && sourceMap . sources [ 0 ] != null
78+ ? sourceContentFor ( sourceMap , sourceMap . sources [ 0 ] )
79+ : null ;
6780 if ( originalContent ) {
6881 return {
6982 source : source . fileName ,
@@ -74,14 +87,14 @@ export function createStackFrame(stackframe: StackFrame, isCompiled: () => boole
7487 } as StackFrameSource ;
7588 }
7689 } else {
77- const result = sourceMap . originalPositionFor ( {
90+ const result = originalPositionFor ( sourceMap , {
7891 line : source . line ,
7992 column : source . column ,
8093 } ) ;
8194 if ( result . source ) {
8295 return {
8396 ...result ,
84- content : sourceMap . sourceContentFor ( result . source , true ) ,
97+ content : sourceContentFor ( sourceMap , result . source ) ,
8598 } as StackFrameSource ;
8699 }
87100 }
0 commit comments