hapijs / good

hapi process monitoring
Other
525 stars 160 forks source link

Error 'const interval = options.ops.interval;' #487

Closed makusan closed 8 years ago

makusan commented 8 years ago

Hi,

I was just following the hapijs tutorial and i got this error after adding the logging part "good". When trying to run the node server, the following errors occurred. What should i do?

$ node server
C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\good\lib\index.js:21
            const interval = options.ops.interval;
                                        ^

TypeError: Cannot read property 'interval' of undefined
    at C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\good\lib\index.js:21:41
    at Items.serial (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\lib\server.js:381:18)
    at iterate (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\node_modules\items\lib\index.js:36:13)
    at Object.exports.serial (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\node_modules\items\lib\index.js:39:9)
    at internals.Server._invoke (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\lib\server.js:378:11)
    at Items.parallel (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\lib\server.js:260:14)
    at done (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\node_modules\items\lib\index.js:63:25)
    at process.nextTick (C:\Users\maku\Documents\NodeProjects\hapijs\myproject\node_modules\hapi\node_modules\catbox-memory\node_modules\hoek\lib\index.js:850:22)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

maku@FALCON MINGW64 ~/Documents/NodeProjects/hapijs/myproject
$ node -v
v6.2.0
arb commented 8 years ago

What version of good? Can I see your config setup?

makusan commented 8 years ago

Hi, here's my config, i'm running nodejs on Windows 10 x64

maku@FALCON MINGW64 ~/Documents/NodeProjects/hapijs/myproject
$ node -v && npm -v
v6.2.0
3.9.0

// Exactly the same from tutorial
// server.js

'use strict';

const Hapi = require('hapi');
const Good = require('good');

const server = new Hapi.Server();
server.connection({ port: 3000 });

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
        reply('Hello, world!');
    }
});

server.route({
    method: 'GET',
    path: '/{name}',
    handler: function (request, reply) {
        reply('Hello, ' + encodeURIComponent(request.params.name) + '!');
    }
});

server.register({
    register: Good,
    options: {
        reporters: {
            console: [{
                module: 'good-squeeze',
                name: 'Squeeze',
                args: [{
                    response: '*',
                    log: '*'
                }]
            }, {
                module: 'good-console'
            }, 'stdout']
        }
    }
}, (err) => {

    if (err) {
        throw err; // something bad happened loading the plugin
    }

    server.start((err) => {

        if (err) {
           throw err;
        }
        server.log('info', 'Server running at: ' + server.info.uri);
    });
});

// package.json : 
{
  "name": "myproject",
  "version": "0.0.1",
  "description": "HapiJS Web App Tutorial",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/makusan/hapijs-tutorial/tutorial.git"
  },
  "author": "Makusan <makufx@gmail.com>",
  "license": "MIT",
  "dependencies": {
    "good": "^7.0.0",
    "good-console": "^6.1.1",
    "good-squeeze": "^3.0.1",
    "hapi": "^13.4.0",
    "inert": "^4.0.0"
  }
}
arb commented 8 years ago

Try adding and empty ops object to your options into good. I think we have a bug here, but I'm trying to just get this working for you right now.

makusan commented 8 years ago

How should i put that? Sorry, kinda new into this.

Thanks for your reply.

arb commented 8 years ago
    options: {
        reporters: {
            console: [{
                module: 'good-squeeze',
                name: 'Squeeze',
                args: [{
                    response: '*',
                    log: '*'
                }]
            }, {
                module: 'good-console'
            }, 'stdout']
        },
       ops: {}
    }
akshayp commented 8 years ago

Looks like these options throw an error for interval being set to an invalid value (Running good@7.0.0 and good-console@6.1.1)

Error: interval must be less than 2147483648

const opts = options: {
    ops: {},
    reporters: {
        console: [{
            module: 'good-console',
            args: [{ log: ['error', 'medium'], response: '*' }]
        }, 'stdout']
    }
}
sjmcdowall commented 8 years ago

Here is a working example of the Good setup for the tutorial - not the ops -> interval .. this runs fine for me. server.register({ register: Good, options: { ops: { interval: 1000 }, reporters: { console: [{ module: 'good-squeeze', name: 'Squeeze', args: [{ response: '*', log: '*' }] }, { module: 'good-console' }, 'stdout'] } }

arb commented 8 years ago

The interval object isn't required. There are defaults and you should only set it if you need something other than the defaults. This bug was fixed in version 7.0.1.

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.