origamitower / folktale

[not actively maintained!] A standard library for functional programming in JavaScript
https://folktale.origamitower.com/
MIT License
2.05k stars 102 forks source link

Exception swallowed in Task #163

Open jmatsushita opened 6 years ago

jmatsushita commented 6 years ago

When using a require()d missing import, which should be undefined, inside a Task the exception is swallowed.

Steps to reproduce

See upcoming test.

Expected behaviour

An exception to be raised

Observed behaviour

The program doesn't raise an exception or not even an unhandledRejection.

Environment

robotlolita commented 6 years ago

Mmh, I'm confused about that PR. The tests pass when fixing the check in the catch branch.

In any case, Task shouldn't be swallowing any errors, but it's quite possible that some weird interaction between Task and Promises is doing that. Hard to say what without more context though.

jmatsushita commented 6 years ago

The conditional assertion was confusing indeed. I've hopefully clarified the intent now with the updated PR description.

yormi commented 6 years ago

I encountered a similar problem if I try to use jsonwebtoken.

No matter if I use Task.fromNodeback(jwt.sign) or make my own task with:

const t = task(resolver =>
    jwt.sign(payload, secret, (err, _) =>
      err ? resolver.reject() : resolver.resolve()
    )

t.run().promise() would resolve but

await t
        .map(_ => { throw new Error('abc') })
        .run()
        .promise()

will swallow the error and hang there.

So far, haven't encounter any problem neither if I use the synchronized version: t = Task.of(jwt.sign(payload, secret)) or any other circumstances. Just with async jwt stuff.

Oh and if I console.log, I can see that the .maps are executed but never .listen neither anything awaiting the promise.

No problem with .listen if not using .promise() not true after all...

node: 9.3.0 OS: Linux folktale: 2.0.1

Hope this helps...

edit: Just tried with data.task and couldn't make it work either =/ Maybe it's the library (don't get how could that be) or me doing something wrong...