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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS crashes because Promise errors are handled using try...catch #1888

Open
DenisVASI9 opened this issue Jun 27, 2023 · 2 comments
Open

Comments

@DenisVASI9
Copy link

DenisVASI9 commented Jun 27, 2023

馃悰 Bug report

Current Behavior

NodeJS crashes because Promise errors are handled using try...catch

Reproducible example

import { Either, tryCatch } from "fp-ts/lib/Either";

function test(error: boolean): Promise<void> {
    return new Promise((resolve, reject) => {
        if (error) {
            return reject();
        }
        return resolve();
    });
}


const testEither = (error: boolean): Either<string, Promise<void>> =>
  tryCatch(
    () => test(error),
    (error) => `${error}`
  );

  console.log(testEither(true))
{ _tag: 'Right', right: Promise { <rejected> undefined } }
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v18.9.0
@samhh
Copy link
Contributor

samhh commented Jun 27, 2023

https://gcanti.github.io/fp-ts/modules/TaskEither.ts.html#trycatch

@DenisVASI9
Copy link
Author

@samhh Hvala brate, sada sve radi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants