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

UnhandledPromiseRejectionWarning #79

Closed
4poc opened this issue Dec 15, 2016 · 7 comments · Fixed by #81
Closed

UnhandledPromiseRejectionWarning #79

4poc opened this issue Dec 15, 2016 · 7 comments · Fixed by #81

Comments

@4poc
Copy link

4poc commented Dec 15, 2016

Node Version: v6.6.0
node-jose: 0.9.1

I have trouble handling malformed data errors with JWE decryption.

Example Code:

const jose = require('node-jose');

const keystore = jose.JWK.createKeyStore();

keystore.generate('oct', 256).
    then(() => {

        jose.JWE.createDecrypt(keystore).decrypt('asdf').
        then((result) => {
            console.log('Result: ', result);
        }).
        catch((err) => {
            console.log('Handled error (decrypt)', err);
        });

    }).
    catch((err) => {
        console.log('Handled error (keystore generate)', err);
    });

This prints:

Handled error (decrypt) Error: no key found
    at processKey (/home/apoc/projects/ms/frontend/node_modules/node-jose/lib/jwe/decrypt.js:157:22)
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:592:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
(node:3169) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token j in JSON at position 0

I can't figure out why this triggers a UnhandledPromiseRejectionWarning? The returned promise should already be rejected at the JSON.parse.

@4poc
Copy link
Author

4poc commented Dec 15, 2016

seems node related, I don't get the warning with node v4.6.2

@linuxwolf
Copy link
Member

Node v6 added this warning if a rejection handler is not present within a tick or two of the promise existing.

I'm not sure how to fix this one, though.

@SimonSchick
Copy link

SimonSchick commented Dec 27, 2016

There is another one seemingly caused by decrypt, more specially decrypt.js:99-100 apparently base64url.decode is returning a buffer instead of a string, I am not sure why the rejection is marked as unhandled however, because it is handled in our code.

I created an issue for the above.

@linuxwolf

There is a missing promise = assigment in jwt/decrypt.js:97 file it seems, you might want to fix that.
https://github.com/cisco/node-jose/blob/master/lib/jwe/decrypt.js#L97

@SimonSchick
Copy link

Additional recommendation: Allow us to set the implementation of Promise you use, this will allow developers choosing the preferred Promise lib, for instance bluebird.

@linuxwolf
Copy link
Member

linuxwolf commented Dec 29, 2016

@SimonSchick please submit a separate issue (or better yet, PR) for the promise enhancement.

As for the broken promise chain in decrypt ... working on a fix now.

@SimonSchick
Copy link

@linuxwolf Release when?

@linuxwolf
Copy link
Member

working on that now

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

Successfully merging a pull request may close this issue.

3 participants