Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Warning on request-internal event #602

Closed
illustratordavid opened this issue Dec 13, 2017 · 11 comments
Closed

Warning on request-internal event #602

illustratordavid opened this issue Dec 13, 2017 · 11 comments

Comments

@illustratordavid
Copy link

I'm trying to resolve why my state is failing using the code in Hapi 17

server.events.on('request-internal', (request, event, tags) => { if (tags.error && tags.state) { if (event.message == "Cannot read property 'state' of undefined") { console.error('state is undefined', tags) } } })

This doesn't produce anything and I get the warnings
(node:22137) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): AssertionError [ERR_ASSERTION]: Unknown event request-internal warning.js:18

(node:22137) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Has anyone else seen this?

@AdriVanHoudt
Copy link

What version of hapi are you using?

@illustratordavid
Copy link
Author

The latest version - 17.1.1

@AdriVanHoudt
Copy link

Do you have a small gist or anything we can reproduce it with?

@bschwartz757
Copy link

bschwartz757 commented May 17, 2018

Hello,

I'm refactoring a server from Hapi v8.4 (I know.... not my server!) to 17.4. The existing implementation uses a handler like so (I changed it from server.on to server.events.on per the docs):

    server.events.on('request-internal', function (request, event, tags) {
        if (tags.error && tags.state) {
            console.error('request-internal', event, tags.error, tags.state);
        }
    });

and I'm getting the same error as @illustratordavid - except that it doesn't mention anything about an unhandled promise rejection. I am, however, using make promises safe, so maybe that's wrapping the error. Here's the error output I'm seeing:
Error: AssertionError [ERR_ASSERTION]: Unknown event request-internal

The only thing I could find in the Hapi docs for this was here - the block just above this anchor shows an example:

server.events.on('request-internal', (request, event, tags) => {

    if (tags.error && tags.state) {
        console.error(event);
    }
});

Also, I did look into where this error is being thrown - appears it's inside node_modules/podium/lib/index.js -> line 259:

    const name = criteria.name;
    const event = this._eventListeners[name];
    **Hoek.assert(event, `Unknown event ${name}`);**

console.log-ing this._eventListeners doesn't show a request-internal. Is this an event that has to be added manually now?

@AdriVanHoudt any idea how to fix this?
Thanks,

@AdriVanHoudt
Copy link

I think you need to

server.events.on({ name: 'request', channels: 'error' }, ...

See https://github.com/hapijs/hapi/blob/62d87f95e98da29298911b9ff33d5b1e28912917/test/request.js#L609
The docs might be outdated cc @hueniverse ?

@bschwartz757
Copy link

@AdriVanHoudt Awesome, thanks for the prompt response!!

I think I may be missing something about what this event is and how it's generated/supposed to be used. My understanding is it's generated internally by Hapi when it makes some kind of internal request and there's an error for some reason? I still don't get the channels concept here... but I guess for request-intenal I'd want to subscribe to the errors channel. Essentially I just want to log these events to the console.

The changelog for hapi 17 does mention this, but is a little cryptic:
Combined 'request', 'request-internal', and 'request-error' into a single event and added channels support.
I guess you have to be a little more familiar with Hapi's logging and channels concepts to get that. Anyways, I'll try your suggestion above.

Thanks again!

@hueniverse
Copy link

The changelog has a detailed description of the changes.

@AdriVanHoudt
Copy link

So the docs are outdated then?

@hueniverse
Copy link

If they still list those events...

@bschwartz757
Copy link

bschwartz757 commented May 21, 2018

@AdriVanHoudt @hueniverse I am interested in getting a better understanding of the 'channels' concept. For example, with something like: server.events.on({ name: 'request-internal', channels: 'error' }, ..., is it correct to assume that request-internal will be generated internally by Hapi, and that Hapi will also create the error channel? Or are those events that I need to create and programmatically dispatch?

EDIT: looks like this is covered in the docs after all: https://hapijs.com/api#-servereventsoncriteria-listener. However, this mentions the following: event name string which can be any of the built-in server events. When I follow the link I am directed to the podium project documentation, but there is no list of the available built-in server events - something like that would be very helpful.

Also, I'm not quite sure how to reconcile the suggested code snippet here: https://github.com/hapijs/hapi/blob/62d87f95e98da29298911b9ff33d5b1e28912917/test/request.js#L609 with the previous version of my code (also shown in the v17.4 docs):

server.events.on('request-internal', (request, event, tags) => {
    if (tags.error && tags.state) {
        console.error(event);
    }
});

I just visited the docs again and saw that in v17.5 there are no longer any references to request-internal... has this been removed? what would be an analogous event?

@hueniverse
Copy link

I fixed the documentation. It will go live when the new version is published.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants