-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
3659a73
to
6b8dbe1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure if this is worth the potential breakage, and instead it might be better to call this behavior out in the documentation?
Most people who write code for the ecosystem are not going to expect an exception here, because the default build of Node.js doesn’t fail this way, so passing the data through unchanged might be the better choice, even if it’s not ideal.
Should it emit a warning instead of throwing an error? IMHO that would be better than failing silently. |
For reference, |
@aduh95 I think both of those options make sense, yes :) |
+1 on the opt-in, I don't think it would be good to add an unexpected exception. As to the name, ICU is technically correct, however, from the builder's point of view the term has been "intl" such as from
So, Node.js was built using the options So, perhaps the option should be called ERR_WITHOUT_INTL or ERR_NO_INTL? However, I see there's already a:
So this (potential) inconsistency is already there. |
5f3fbc8
to
189677f
Compare
I have removed the exception throwing, instead, a message is printed to stderr notifying the user that the operation is a no-op. I'm not 100% satisfied with this solution as it doesn't create a proper warning that can be inhibited with a flag, but given the fact that the function doesn't have access an I'd argue that this is better than the current behaviour (no warning at all). What do y'all think? |
@addaleax @srl295 @TimothyGu @joyeecheung @jasnell Thoughts on this approach? |
Also, is this still semver-major since it doesn't throw anymore but merely prints a warning? I'm inclined to say "technically, yes, so let's be cautious and treat it as a breaking change" but I also wonder if that's a bit much.... |
It would be nice if these warnings were emitted either via 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 :)). |
@@ -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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) orProcessEmitWarning()
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, ?)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
@aduh95 ... did you still want to pursue this? |
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Continuation of: nodejs#35099 Signed-off-by: Darshan Sen <[email protected]>
Continuation of: nodejs#35099 Signed-off-by: Darshan Sen <[email protected]>
Continuation of: nodejs#35099 Signed-off-by: Darshan Sen <[email protected]> PR-URL: nodejs#38789 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Continuation of: #35099 Signed-off-by: Darshan Sen <[email protected]> PR-URL: #38789 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Continuation of: #35099 Signed-off-by: Darshan Sen <[email protected]> PR-URL: #38789 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Continuation of: #35099 Signed-off-by: Darshan Sen <[email protected]> PR-URL: #38789 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Continuation of: nodejs#35099 Signed-off-by: Darshan Sen <[email protected]> PR-URL: nodejs#38789 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
ICU dependent functions throw an ERR_NO_ICU error on Node.js versions
compiled without ICU.
FYI the current behaviour is to return the input string unchanged when ICU is not available:
That's – to say the least – unexpected taht the function silently fails. This PR addresses that:
This is a semver-major change.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes