Skip to content

Promises on prerequisites makes handler to swallow exceptions #2771

Closed
@nakardo

Description

@nakardo

I've this issue when using Promises on a prerequisite handler and throwing an error from a handler.

var Promise = require('promise');


exports.register = function (server, options, next) {

    var pre = function (request, reply) {

        return reply(Promise.resolve('value'));
    };

    server.route({
        method: 'GET',
        path: '/bar',
        config: {
            pre: [
                { method: pre, assign: 'pre' }
            ],
            handler: function (request, reply) {

                // throws here will get swallowed

                throw new Error('will timeout');
                return reply();
            }
        }
    });

    return next();
};

exports.register.attributes = {
    pkg: require('./package.json')
};

Replying with a literal value on the pre() does it make it work. Using Promises on the handler will too, but it sounds more like a workaround to me.

Here's the dependencies I'm using:

code@1.5.0 node_modules/code
└── hoek@2.16.2

promise@7.0.4 node_modules/promise
└── asap@2.0.3

hapi@9.3.1 node_modules/hapi
├── ammo@1.0.1
├── cryptiles@2.0.4
├── topo@1.0.3
├── peekaboo@1.0.0
├── items@1.1.0
├── kilt@1.1.1
├── catbox-memory@1.1.2
├── accept@1.1.0
├── call@2.0.2
├── statehood@2.1.1
├── boom@2.8.0
├── iron@2.1.3
├── shot@1.6.0
├── qs@4.0.0
├── hoek@2.14.0
├── catbox@6.0.0
├── mimos@2.0.2 (mime-db@1.18.0)
├── subtext@2.0.0 (content@1.0.2, wreck@6.1.0, pez@1.0.0)
├── joi@6.6.1 (isemail@1.1.1, moment@2.10.6)
└── heavy@3.0.0 (joi@5.1.0)

lab@5.17.0 node_modules/lab
├── diff@1.4.0
├── items@1.1.1
├── json-stringify-safe@5.0.1
├── bossy@1.0.3
├── eslint-config-hapi@2.0.1
├── hoek@2.16.2
├── espree@2.2.5
├── mkdirp@0.5.1 (minimist@0.0.8)
├── source-map-support@0.3.2 (source-map@0.1.32)
├── jslint@0.9.3 (exit@0.1.2, nopt@3.0.4, readable-stream@1.0.33, glob@4.5.3)
├── handlebars@4.0.2 (async@1.4.2, source-map@0.4.4, optimist@0.6.1, uglify-js@2.4.24)
├── eslint@1.4.3 (escape-string-regexp@1.0.3, object-assign@2.1.1, path-is-absolute@1.0.0, path-is-inside@1.0.1, xml-escape@1.0.0, user-home@1.1.1, strip-json-comments@1.0.4, estraverse-fb@1.3.1, globals@8.8.0, estraverse@4.1.0, text-table@0.2.0, is-resolvable@1.0.0, shelljs@0.3.0, debug@2.2.0, glob@5.0.14, chalk@1.1.1, optionator@0.5.0, lodash.merge@3.3.2, lodash.clonedeep@3.0.2, lodash.omit@3.1.0, doctrine@0.6.4, minimatch@2.0.10, concat-stream@1.5.0, is-my-json-valid@2.12.2, to-double-quotes@1.0.1, to-single-quotes@1.0.3, file-entry-cache@1.2.3, inquirer@0.9.0, js-yaml@3.4.2, escope@3.2.0)
└── eslint-plugin-hapi@1.2.0 (hapi-scope-start@1.1.2, hapi-capitalize-modules@1.1.1, no-shadow-relaxed@1.0.1)

I can upload an small repo with a few tests if it helps.

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions