Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: show input in parse error message #11934

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Mar 20, 2017

Show the input in URL parse errors so it's easier to debug

Before

> new URL('test')
TypeError: Invalid URL

After

> new URL('test')
TypeError: Invalid URL: test

Also put the error handling in another callback of binding.parse(), if it is unspecified, nothing will be done.

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)

url

@nodejs/url

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. dont-land-on-v4.x whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Mar 20, 2017
@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

Previous CI is unsuccessful. New CI: https://ci.nodejs.org/job/node-test-pull-request/6930/

@jasnell
Copy link
Member

jasnell commented Mar 20, 2017

+1 on this... tho I'm curious if we shouldn't also make it possible to access it programmatically. e.g.

try {
  new URL('test');
} catch (e) {
  console.log(e.input);
}

/cc @addaleax

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM with green CI

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

LGTM.

src/node_url.cc Outdated
String::NewFromUtf8(env->isolate(),
input,
v8::NewStringType::kNormal).ToLocalChecked();
(void)error_cb.As<Function>()->Call(context, recv, 2, argv);
Copy link
Member

Choose a reason for hiding this comment

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

I know it was there already, but using arraysize(argv) should prevent the need for a hardcoded array length.

@@ -196,16 +188,12 @@ function onParsePathComplete(flags, protocol, username, password,

function onParseSearchComplete(flags, protocol, username, password,
host, port, path, query, fragment) {
if (flags & binding.URL_FLAGS_FAILED)
return;
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure I’m not missing something – these are dropped because the on*Complete functions are not called in the case of errors anymore, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also curious about it. Is that why the search setter doesn't need to have onParseError in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the completion and the errors are handled in different callbacks, since it doesn't really make sense to pass all these parsed parts to an error callback anyway.

The setters are ignoring errors per the spec at the moment, so they don't have error callbacks.

@addaleax
Copy link
Member

+1 on this... tho I'm curious if we shouldn't also make it possible to access it programmatically

Sure, why not? Making stuff programmatically accessible is always good.

@joyeecheung
Copy link
Member Author

Use arraysize() per @TimothyGu 's suggestion and add error.input per @jasnell 's suggestion. PTAL, thanks!

New CI: https://ci.nodejs.org/job/node-test-pull-request/6953/

@jasnell
Copy link
Member

jasnell commented Mar 22, 2017

This will need a rebase

@joyeecheung
Copy link
Member Author

Rebased. Can anyone approved this before take a look again? Thanks!

New CI: https://ci.nodejs.org/job/node-test-pull-request/6994/

@jasnell
Copy link
Member

jasnell commented Mar 23, 2017

Still LGTM

jasnell pushed a commit that referenced this pull request Mar 23, 2017
PR-URL: #11934
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
@jasnell
Copy link
Member

jasnell commented Mar 23, 2017

Landed in ee19e29

@jasnell jasnell closed this Mar 23, 2017
MylesBorins pushed a commit that referenced this pull request Mar 28, 2017
PR-URL: #11934
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Mar 28, 2017
@italoacasas italoacasas mentioned this pull request Apr 10, 2017
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants