hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

Promise Error doesn't make it to Catch #96

Closed dhershman1 closed 7 years ago

dhershman1 commented 7 years ago

It doesn't seem like the promise returned by glue makes it to the catch you add onto compose, If an issue happens within the config (say I were to change one of my plugin names to cheese) you get back an unhandled promise rejection.

Please note: This applies for any issue not just plugin registering.

Example setup:

const manifest = require('./glue.config.js');
const glue = require('glue');

glue.compose(manifest).then(server => {
    server.start(error => {
        if (error) {
            throw error;
        }

        console.log(`Server running at: ${server.info.uri}`);
    });
})
.catch(err => {
    throw err;
});

The working glue config example:

module.exports = {
    connections: [{
        port: process.env.APP_PORT || 5000
    }],
    registrations: [{
        plugin: 'h2o2'
    }]
};

The broken glue config example

module.exports = {
    connections: [{
        port: process.env.APP_PORT || 5000
    }],
    registrations: [{
        plugin: 'cheese'
    }]
};
devinivy commented 7 years ago

If you throw in a catch block, then you'll create another rejected promise. My guess is that if you log the error rather than throw it, you will not have an unhandled rejection.

dhershman1 commented 7 years ago

Not sure why I didn't think to swap out that throw. I've been looking at this project for too long. Oh well, thanks for the clear up to my oopsies. ¯_(ツ)_/¯

devinivy commented 7 years ago

Sure thing! :D 🍻

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.