Skip to content

Conversation

Shadowbeetle
Copy link
Contributor

@Shadowbeetle Shadowbeetle commented May 18, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

async-hooks

[refack edit: removed documentation checkbox, as it seems it is not needed for this PR]

@nodejs-github-bot nodejs-github-bot added the async_hooks Issues and PRs related to the async hooks subsystem. label May 18, 2017
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because without them it will accept false without throwing, which I assume is not the expected behaviour

Copy link
Contributor

@mscdex mscdex May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Can we at least use init !== undefined instead? That is the form we use elsewhere in core.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you re-phrase these using assert.throws? e.g.

assert.throws(() => {
  async_hooks.createHook({ init: 1 });
}, /^TypeError: init must be a function$/);

(Also, please make sure that make lint passes :))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have updated the commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this block copy-pased or did you check that it is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shame on me, completely copy-pasted and unnecessary. I have updated the commit.

@AndreasMadsen
Copy link
Member

AndreasMadsen commented May 18, 2017

Thanks for taking the time to fix this.

Because without them it will accept false without throwing, which I assume is not the expected behaviour

Could you add those details to the commit message, "test: add constructor test to async-hooks" is a little vague. Since this changes something in the actual async_hooks code you should also prefix the commit message with async_hooks: instead of test: .

Copy link
Contributor

@refack refack May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shadowbeetle you gave false as a previously failing argument. Could you add a set of tests with false?
This could be done in a double loop:

for (let badArg of [1, false, true, null, undefined, 'hello']) {
  for (let field of ['init', 'before', 'after', 'destroy']) {
    assert.throws(() => {
      async_hooks.createHook({ [field]: badArg });
    }, /^TypeError: before must be a function$/);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@refack Thanks, I have included this with a minor change in the commit.

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@refack
Copy link
Contributor

refack commented May 19, 2017

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a couple of lines describing what this is testing
https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the dangling , is a lint error

@Shadowbeetle
Copy link
Contributor Author

Sorry, an extra space sneaked in that broke the lint

@AndreasMadsen
Copy link
Member

AndreasMadsen commented May 19, 2017

@Shadowbeetle Sorry if what I said was poorly explained, but we need to conform to the commit message guidelines, you can read them here https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#commit-message-guidelines

Something like this should be fine:

async_hooks: add constructor check to AsyncHook

This fixes the async_hooks.AsyncHook constructor such that it throws an error
when provided with falsy values other than undefined.

This fixes the async_hooks.AsyncHook constructor such that it throws an error
when provided with falsy values other than undefined.
@Shadowbeetle
Copy link
Contributor Author

@AndreasMadsen I see, sorry I should have read the guidelines more thoroughly. Updated the commit message.

@AndreasMadsen
Copy link
Member

AndreasMadsen pushed a commit that referenced this pull request May 21, 2017
This fixes the async_hooks.AsyncHook constructor such that it throws an
error when provided with falsy values other than undefined.

PR-URL: #13096
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
@AndreasMadsen
Copy link
Member

AndreasMadsen commented May 21, 2017

@Shadowbeetle Thanks for your contribution, the commit landed in 6fb27af

PS: I fixed the commit message linebreak and test comment on merge.

@refack
Copy link
Contributor

refack commented May 21, 2017

Congrats @Shadowbeetle on your first contribution 🥇
And @AndreasMadsen on your first land 😉

@AndreasMadsen
Copy link
Member

AndreasMadsen commented May 21, 2017

@refack Thanks. I have landed a few commits, but it has been a while :)

@Shadowbeetle
Copy link
Contributor Author

thanks to everybody for all the help

@jasnell jasnell mentioned this pull request May 28, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins
Copy link
Contributor

This should likely be part of a larger sync hooks backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants