Skip to content

"Convert to async function" does not handle .then(fn1, fn2) correctly #27621

@mjbvz

Description

@mjbvz

From @MikeyBurkman on October 8, 2018 21:37

  • VSCode Version: 1.28.0
  • OS Version: OSX High Sierra

Steps to Reproduce:

  1. The code in the gif on https://code.visualstudio.com/updates/v1_28#_convert-to-async-function is actually wrong
  2. When doing .then(fn1, fn2), the second arg fn2 should NOT be called if there's an error in fn1.

Sample code:

'use strict';

const promise = () => new Promise((res) => setTimeout(res, 500));

const fSync = function() {
  return promise().then(
    () => {
      throw new Error('Failure!');
    },
    () => null
  );
};

// This function was created by copying/pasting the above function, and applying the "convert to async function" helper
const fAsync = async function() {
  try {
    await promise();
    throw new Error('Failure!');
  } catch (e) {
    return null;
  }
};

fSync()
  .then(() => console.log('SYNC Sucess?'))
  .catch((err) => console.log('SYNC Got an error', err));

fAsync()
  .then(() => console.log('ASYNC Sucess?'))
  .catch((err) => console.log('ASYNC Got an error', err));

Expected output:

  • Both should output "[A]SYNC Got an error Error: Failure!"

Actual output:

  • SYNC Got an error Error: Failure!
  • ASYNC Success?

Copied from original issue: microsoft/vscode#60201

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions