hapijs / hapi

The Simple, Secure Framework Developers Trust
https://hapi.dev
Other
14.61k stars 1.34k forks source link

Error: Uncaught error: Invalid nested use of protect.run() #1740

Closed joshua-mcginnis closed 10 years ago

joshua-mcginnis commented 10 years ago

I'm getting this error in Hapi 6.0.2.

140623/172346.510, internalError, message: Uncaught error: Invalid nested use of protect.run() stack: Error: Uncaught error: Invalid nested use of protect.run()
    at Object.exports.assert (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/node_modules/hoek/lib/index.js:421:11)
    at internals.Protect.run (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/protect.js:38:10)
    at Object.exports.invoke (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/handler.js:376:22)
    at internals.Request._reply (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/request.js:359:13)
    at /Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/request.js:327:18
    at /Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/node_modules/async/lib/async.js:151:21
    at failActionNext (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/payload.js:43:20)
    at /Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/payload.js:156:24
    at Object.internals.jsonParse (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/payload.js:278:16)
    at Object.internals.object (/Users/jmcginnis/sandbox/caa/app-clients/node_modules/hapi/lib/payload.js:259:26)
joshua-mcginnis commented 10 years ago

Fixed on our side.

Kevin-A commented 10 years ago

How did you solve this?

I'm having the same error when serving files. More specifically, serving angular.js. (I serve the static index.html page, which calls all static files.

// Load angular and enable static files
    { 
        method: 'GET', 
        path: '/', 
        config: {
            auth: false,
            handler: function (request, reply) {
                reply.file('../../ng-boilerplate/build/index.html');
            }
        } 
    },
    {
        method: "GET",
        path: "/{path*}",
        config: {
            auth: false,
            handler: {
                directory: {
                    path: "../../ng-boilerplate/build",
                    listing: false,
                    index: false
                }
            }
        }
    }
hueniverse commented 10 years ago

@Kevin-A you are getting the above error from this route code? Can you post a full example on how to reproduce your error?

Kevin-A commented 10 years ago

Yes, with the above code, loading the default ng-boilerplate code. I'm using an old version of Hapi though (3.1.x) due to Yar not being Hapi 6 ready. This error happens when using Chrome and refreshing the page (localhost:8002/ in my case).

(Removed all excessive code)

// index.js
var Hapi = require('hapi');
var Config = require('./config');
var Routes = require('./routes');

// Create a server with a host and port
var server = Hapi.createServer(Config.server.hostname, Config.server.port, {
    cors: Config.server.cors
});

//connect the routes
server.route(Routes.endpoints);

// Start the server
server.start(function() {
    console.log("The server has started on port: " + server.info.port);
});
// routes.js

/**
 * Contains the list of all routes, i.e. methods, paths and the config functions
 * that take care of the actions
 */
exports.endpoints = [
    // Load angular and enable static files
    { 
        method: 'GET', 
        path: '/', 
        config: {
            auth: false,
            handler: function (request, reply) {
                reply.file('../../ng-boilerplate/build/index.html');
            }
        } 
    },
    {
        method: "GET",
        path: "/{path*}",
        config: {
            auth: false,
            handler: {
                directory: {
                    path: "../../ng-boilerplate/build",
                    listing: false,
                    index: false
                }
            }
        }
    }
];
hueniverse commented 10 years ago

Yar is on 6.x now. Can you upgrade and retry?

Kevin-A commented 10 years ago

I'm not able to recreate the error, so it seems fixed in Hapi 6.2.x.