GeezerVison is showing github.com — src,lib: print prinstine source when source map source not found · jigfox/node@0a2c910
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/source_map/prepare_stack_trace.js +7-6Lines changed: 7 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -139,17 +139,21 @@ function getErrorSource( | 139 | 139 | originalLine, | 140 | 140 | originalColumn | 141 | 141 | ) { | 142 | | - let exceptionLine = ''; | 143 | 142 | const originalSourcePathNoScheme = | 144 | 143 | StringPrototypeStartsWith(originalSourcePath, 'file://') ? | 145 | 144 | fileURLToPath(originalSourcePath) : originalSourcePath; | 146 | 145 | const source = getOriginalSource( | 147 | 146 | sourceMap.payload, | 148 | 147 | originalSourcePath | 149 | 148 | ); | | 149 | + if (typeof source !== 'string') { | | 150 | + return; | | 151 | + } | 150 | 152 | const lines = RegExpPrototypeSymbolSplit(/\r?\n/, source, originalLine + 1); | 151 | 153 | const line = lines[originalLine]; | 152 | | - if (!line) return exceptionLine; | | 154 | + if (!line) { | | 155 | + return; | | 156 | + } | 153 | 157 |
| 154 | 158 | // Display ^ in appropriate position, regardless of whether tabs or | 155 | 159 | // spaces are used: | @@ -161,7 +165,7 @@ function getErrorSource( | 161 | 165 | } | 162 | 166 | prefix = StringPrototypeSlice(prefix, 0, -1); // The last character is '^'. | 163 | 167 |
| 164 | | - exceptionLine = | | 168 | + const exceptionLine = | 165 | 169 | `${originalSourcePathNoScheme}:${originalLine + 1}\n${line}\n${prefix}^\n\n`; | 166 | 170 | return exceptionLine; | 167 | 171 | } | @@ -184,10 +188,7 @@ function getOriginalSource(payload, originalSourcePath) { | 184 | 188 | source = readFileSync(originalSourcePathNoScheme, 'utf8'); | 185 | 189 | } catch (err) { | 186 | 190 | debug(err); | 187 | | - source = ''; | 188 | 191 | } | 189 | | - } else { | 190 | | - source = ''; | 191 | 192 | } | 192 | 193 | return source; | 193 | 194 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_errors.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -105,7 +105,9 @@ static std::string GetErrorSource(Isolate* isolate, | 105 | 105 | if (has_source_map_url && env != nullptr && env->source_maps_enabled()) { | 106 | 106 | std::string source = GetSourceMapErrorSource( | 107 | 107 | isolate, context, message, added_exception_line); | 108 | | - return *added_exception_line ? source : sourceline; | | 108 | + if (*added_exception_line) { | | 109 | + return source; | | 110 | + } | 109 | 111 | } | 110 | 112 |
| 111 | 113 | // Because of how node modules work, all scripts are wrapped with a | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/source-map/no-source.js +9Lines changed: 9 additions & 0 deletions Collapse file Copy file name to clipboardExpand all lines: test/fixtures/source-map/no-source.js.map +1Lines changed: 1 addition & 0 deletions Collapse file Copy file name to clipboard +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +function Throw() { | | 2 | + throw new Error('foo'); | | 3 | +} | | 4 | + | | 5 | +Throw(); | | 6 | + | | 7 | +// To recreate: | | 8 | +// | | 9 | +// npx tsc --outDir test/fixtures/source-map --sourceMap test/fixtures/source-map/no-source.ts | | 10 | +// rename the "source.[0]" to "file-not-exists.ts" |
Collapse file Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --enable-source-maps | | 2 | + | | 3 | +'use strict'; | | 4 | +require('../common'); | | 5 | + | | 6 | +require('../fixtures/source-map/no-source.js'); |
Collapse file Copy file name to clipboard +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +*no-source.js:2 | | 2 | + throw new Error('foo'); | | 3 | + ^ | | 4 | + | | 5 | +Error: foo | | 6 | + at Throw (*file-not-exists.ts:2:9) | | 7 | + at Object.<anonymous> (*file-not-exists.ts:5:1) | | 8 | + at Module._compile (node:internal/modules/cjs/loader:*) | | 9 | + at Module._extensions..js (node:internal/modules/cjs/loader:*) | | 10 | + at Module.load (node:internal/modules/cjs/loader:*) | | 11 | + at Module._load (node:internal/modules/cjs/loader:*) | | 12 | + at Module.require (node:internal/modules/cjs/loader:*) | | 13 | + at require (node:internal/modules/cjs/helpers:*) | | 14 | + at Object.<anonymous> (*source_map_no_source_file.js:6:1) | | 15 | + at Module._compile (node:internal/modules/cjs/loader:*) | | 16 | + | | 17 | +Node.js * |
|