-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
test,module: make message check MUI dependent #13393
Conversation
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.
Explaining + nits
// if we don't know a priori what the error would be, we accept anything | ||
const dlerror_msg = error_desc[process.platform] || ['']; | ||
|
||
// On Windows error message are MUI dependent |
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.
/s/message/messages
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.
and a comma after Windows
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.
addressed
|
||
assert.throws( | ||
() => { require('../fixtures/module-loading-error.node'); }, | ||
() => { | ||
require('../fixtures/module-loading-error.node'); |
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.
putting it in a separate line makes for easy breakpoint setting.
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.
if (dlerror_msg && !dlerror_msg.some((msg) => e.message.includes(msg))) | ||
return false; | ||
if (e.name !== 'Error') | ||
if (localeOk && !dlerror_msg.some((msg) => e.message.includes(msg))) |
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.
replace dlerror_msg
truthy check for a trivial fallback (Line 34) mostly for keeping line short.
return false; | ||
return true; | ||
return e.name === 'Error'; |
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.
simplify
'powershell -NoProfile -ExecutionPolicy Unrestricted -c' + | ||
' "(Get-UICulture).TwoLetterISOLanguageName"'; | ||
try { | ||
localeOk = execSync(powerShellFindMUI).toString('utf8') === 'en'; |
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 fear this might actually be 'en\r\n'
. Maybe .startsWith('en')
, or even .includes('en')
, or trim
the output?
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.
Ack.
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.
Just discovered that this method is not 100% accurate (I changed the locale, logged off and back in without rebooting), but I think it is close enough.
> require('./test/fixtures/module-loading-error.node')
Error: %1 is not a valid Win32 application.
\\?\E:\node\test\fixtures\module-loading-error.node
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at repl:1:1
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:96:12)
>
(To exit, press ^C again or type .exit)
>
E:\node>powershell -NoProfile -ExecutionPolicy Unrestricted -c "(Get-UICulture).TwoLetterISOLanguageName"
de
Will approve if CI passes.
|
||
const error_desc = { | ||
win32: ['%1 is not a valid Win32 application'], | ||
linux: ['file too short', 'Exec format error'], | ||
sunos: ['unknown file type', 'not an ELF file'], | ||
darwin: ['file too short'] | ||
}; | ||
const dlerror_msg = error_desc[process.platform]; | ||
// if we don't know a priori what the error would be, we accept anything | ||
const dlerror_msg = error_desc[process.platform] || ['']; |
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.
Maybe use camelCase (dlErrorMsg
) for consistency while you are at it?
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.
s/if/If and add a period at the end
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.
Thank you for implementing this!
|
||
const error_desc = { | ||
const errorMsgsByPlafrom = { |
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.
errorMsgsByPlafrom
-> errorMsgsByPlatform
(and below)
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.
in for penny in for a pound: errorMessagesByPlatform
|
||
assert.throws( | ||
() => { require('../fixtures/module-loading-error.node'); }, | ||
() => { | ||
require('../fixtures/module-loading-error.node'); |
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.
adb46b5
to
6ee5498
Compare
'"(Get-UICulture).TwoLetterISOLanguageName"'; | ||
try { | ||
// If MUI != 'en' we'll ignore the content of the message | ||
localeOk = execSync(powerShellFindMUI).toString('utf8').trim() === 'en'; |
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.
If this line fails and we hit the catch, won't localeOk
still be true
rather than false
?
i.e. should you do this?
if (common.isWindows) {
+ localeOk = false;
const powerShellFindMUI =
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.
Intentionally I chose to be strict. the less use of the "escape hatch" the better the coverage 🤔
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.
If the powershell script fails will it log an error to the console? If so then I guess that's fine.
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.
Yea because execSync pipes stderr from the child we get the error (this one is a synthetic syntax error):
C:\bin\dev\node\node.exe D:\code\node\test\parallel\test-module-loading-error.js
Get-UICulture2 : The term 'Get-UICulture2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:2
+ (Get-UICulture2).TwoLetterISOLanguageName
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-UICulture2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Process finished with exit code 0
Notice that the exit code is 0
PR-URL: nodejs#13393 Fixes: nodejs#13376 Reviewed-By: Tobias Nießen <[email protected]>
6ee5498
to
30a20bd
Compare
Landed in 30a20bd |
PR-URL: #13393 Fixes: #13376 Reviewed-By: Tobias Nießen <[email protected]>
Should this be backported to v6.x? |
Yes. Does not land cleanly, I will backport. |
Fixes: #13376
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test,module