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: make ICU-dependent functions warn for node compiled --without-intl #35099

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,13 @@ bool ToASCII(const std::string& input, std::string* output) {
#else
// Intentional non-ops if ICU is not present.
bool ToUnicode(const std::string& input, std::string* output) {
std::cerr << "Warning: Cannot convert to unicode when intl is disabled!\n";
Copy link
Member

Choose a reason for hiding this comment

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

These definitely would need to use the emitWarning() mechanism. Also, I'd prefer if these were opt-in and gated by a command line flag.

Copy link
Member

@srl295 srl295 Oct 1, 2020

Choose a reason for hiding this comment

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

It would be nice if these warnings were emitted either via process.emitWarning() in JS (it’s okay to create wrapper functions for --without-intl builds imo) or ProcessEmitWarning() in C++ instead, because that way this works with --no-warning, --trace-warning, process.on('warning'), etc.

Im not familiar with those functions, but it does sound better than just printf(stderr
Does emitwarning elide duplicate warnings? i.e. only print a warning once?

Also, yes, I think we should treat this as semver-major. Apart from that, I have no strong opinions here (except for those that I already voiced and that have been addressed :)).

I think it is major because it's long standing behavior.

( @aduh95 out of curiosity, just to keep myself up to date, what is the major use case that you see for without-intl — smaller size, and/or embedded devices, ?)

Copy link
Member

Choose a reason for hiding this comment

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

The emitWarning() API does a number of things... (a) it ensures that all warnings are emitted in a consistent format, (b) it allows warnings to be supressed using command-line flag or environment variables, (b) it forwards the warnings to the process.on('warning') event which is emitted even if the warning output to the console has been disabled (allowing warnings to be logged using third party tools). It does not currently limit warnings to be printed only once unless those are DeprecationWarning or ExperimentalWarning but that is something we can look at later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what is the major use case that you see for without-intl?

@srl295 As a matter of fact, I don't use it :) I stumbled upon this weird behavior when working on #35091, so I figure that was probably not intentional.

@jasnell do you know if emitWarning API is available from C++-land and how to access it? I agree that is the "correct" way to do it, but I didn't manage to get it working.

Another approach I have thought of would be to call the punycode JS module, but again I don't know if that's possible from C++-land. That would remove the need for a warning (or a throw).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, do a search in src for ProcessEmitWarning and you'll see how to make that happen

*output = input;
return true;
}

bool ToASCII(const std::string& input, std::string* output) {
std::cerr << "Warning: Cannot convert to ASCII when intl is disabled!\n";
*output = input;
return true;
}
Expand Down