diff options
author | 2023-08-19 22:58:43 -0700 | |
---|---|---|
committer | 2023-08-24 20:11:20 -0700 | |
commit | 6313655c8e0d5bb0378029199fa329f3750f6ca6 (patch) | |
tree | cf8cd567b040929d3a76a6af0ca39b5bd879f671 /packages/bun-debug-adapter-protocol/debugger/sourcemap.ts | |
parent | f0ebdfff748f4c429206a8ebc6b70c6342f8de2c (diff) | |
download | bun-6313655c8e0d5bb0378029199fa329f3750f6ca6.tar.gz bun-6313655c8e0d5bb0378029199fa329f3750f6ca6.tar.zst bun-6313655c8e0d5bb0378029199fa329f3750f6ca6.zip |
Make source maps safer if exception occurs
Diffstat (limited to '')
-rw-r--r-- | packages/bun-debug-adapter-protocol/debugger/sourcemap.ts | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts b/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts index df0fdc215..1e04e56f4 100644 --- a/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts +++ b/packages/bun-debug-adapter-protocol/debugger/sourcemap.ts @@ -37,29 +37,45 @@ class ActualSourceMap implements SourceMap { } generatedPosition(line?: number, column?: number, url?: string): Position { - const source = this.#getSource(url); - const { line: gline, column: gcolumn } = this.#sourceMap.generatedPositionFor({ - line: line ?? 0, - column: column ?? 0, - source, - }); - console.log(`[sourcemap] -->`, { source, url, line, column }, { gline, gcolumn }); - return { - line: gline || 0, - column: gcolumn || 0, - }; + try { + const source = this.#getSource(url); + const { line: gline, column: gcolumn } = this.#sourceMap.generatedPositionFor({ + line: line ?? 0, + column: column ?? 0, + source, + }); + console.log(`[sourcemap] -->`, { source, url, line, column }, { gline, gcolumn }); + return { + line: gline || 0, + column: gcolumn || 0, + }; + } catch (error) { + console.error(error); + return { + line: line || 0, + column: column || 0, + }; + } } originalPosition(line?: number, column?: number): Position { - const { line: oline, column: ocolumn } = this.#sourceMap.originalPositionFor({ - line: line ?? 0, - column: column ?? 0, - }); - console.log(`[sourcemap] <--`, { line, column }, { oline, ocolumn }); - return { - line: oline || 0, - column: ocolumn || 0, - }; + try { + const { line: oline, column: ocolumn } = this.#sourceMap.originalPositionFor({ + line: line ?? 0, + column: column ?? 0, + }); + console.log(`[sourcemap] <--`, { line, column }, { oline, ocolumn }); + return { + line: oline || 0, + column: ocolumn || 0, + }; + } catch (error) { + console.error(error); + return { + line: line || 0, + column: column || 0, + }; + } } } |