Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger pauses on promise rejection even though it is handled/caught (TypeScript) #50310

Closed
eyelidlessness opened this issue May 22, 2018 · 2 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues *duplicate Issue identified as a duplicate of another issue(s)

Comments

@eyelidlessness
Copy link

Issue Type: Bug

When I'm debugging code that wraps a synchronous function in an async function, if the synchronous function throws and an async caller catches, the debugger treats error/rejection as unhandled.

Previously, I had seen this issue when an error was thrown synchronously within an async function before an await (as described in #5213 (comment)). I was able to fix the problem by making the function in question synchronous (its async behavior had been refactored out already). But the problem has reappeared after I restarted VSCode yesterday (so I have to figure it's related to an update that may have been installed on restart?).

Repro code (compiler target is es2016):

const syncThrowFn = () => {
    // Debugger pauses here
    throw new Error('welp');
};

const wrapAsAsync = <T extends Function>(fn: T) => {
    return async () => {
        return fn();
    };
};

const wrappedAsyncThrowFn = wrapAsAsync(syncThrowFn);

const asyncFn = async (): Promise<Error | void> => {
    try {
        await wrappedAsyncThrowFn();
    }
    catch (error) {
        return error;
    }
};

asyncFn().then((error: Error) => {
    // Logs the error as expected
    console.log('error', error);
});

"Uncaught Exceptions" is checked, "All Exceptions" is not.

I'm not sure this is related to to #1746 because:

  1. The debugger correctly identifies the error (it's not undefined).
  2. The debugger correctly identifies the pause as being caused by a promise rejection (it says "paused on promise rejection" in the top of the Call Stack panel.

VS Code version: Code 1.23.1 (d0182c3, 2018-05-10T16:03:31.083Z)
OS version: Darwin x64 15.6.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz (8 x 2800)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
rasterization: enabled
video_decode: enabled
video_encode: enabled
vpx_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 4, 4, 4
Memory (System) 16.00GB (0.25GB free)
Process Argv /Users/gnosis/Applications/Development/Visual Studio Code.app/Contents/MacOS/Electron
Screen Reader no
VM 0%
Extensions (14)
Extension Author (truncated) Version
output-colorizer IBM 0.1.2
bbcode Squ 0.0.2
gitlens eam 8.3.2
flow-for-vscode flo 0.8.1
theme-macos-classic hua 1.1.1
theme-karyfoundation-themes kar 18.0.1
camelcasenavigation map 0.3.42
sidetest mat 1.1.0
theme-monokai-pro-vscode mon 1.1.6
typescript-javascript-grammar ms- 0.0.41
debugger-for-chrome msj 4.4.3
vscode-icons rob 7.23.0
trailing-spaces sha 0.2.11
cursor-align yo1 1.0.4

(1 theme extensions excluded)

@eyelidlessness
Copy link
Author

It's possible I'm misunderstanding what's covered by #1746. If so I'd understand if this is closed as duplicate. But if this is in fact covered by #1746, it seems that issue should be marked as a bug, not as a feature request. It seems pretty clear that it's a defect that handled promise rejections are being treated as uncaught.

@weinand weinand added the debug Debug viewlet, configurations, breakpoints, adapter issues label May 23, 2018
@roblourens
Copy link
Member

This is still #1746. I don't have a good way to fix it, I'm really at the mercy of the runtime, this is why chrome devtools shows the same behavior. The way TS downcompiles async/await, the runtime doesn't actually know whether the error is handled later on or not. If you run this using native async/await, it works as expected.

@roblourens roblourens added the *duplicate Issue identified as a duplicate of another issue(s) label May 25, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues *duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants