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

test,module: make message check MUI dependent #13393

Merged
merged 1 commit into from
Jun 5, 2017

Conversation

refack
Copy link
Contributor

@refack refack commented Jun 2, 2017

Fixes: #13376

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

test,module

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

Copy link
Contributor Author

@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.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/s/message/messages

Copy link
Contributor Author

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

Copy link
Contributor Author

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');
Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

This seems like an unnecessary change. Not sure about other debuggers, but chrome://inspect allows you to set breakpoints on statements within a line:

image

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)))
Copy link
Contributor Author

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';
Copy link
Contributor Author

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';
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack.

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

Copy link
Member

@tniessen tniessen left a 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] || [''];
Copy link
Member

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?

Copy link
Member

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

@tniessen tniessen added the windows Issues and PRs related to the Windows platform. label Jun 2, 2017
@mscdex mscdex added the module Issues and PRs related to the module subsystem. label Jun 2, 2017
@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

@refack
Copy link
Contributor Author

refack commented Jun 2, 2017

Copy link
Member

@tniessen tniessen left a 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 = {
Copy link
Member

Choose a reason for hiding this comment

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

errorMsgsByPlafrom -> errorMsgsByPlatform (and below)

Copy link
Contributor Author

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');
Copy link
Member

Choose a reason for hiding this comment

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

This seems like an unnecessary change. Not sure about other debuggers, but chrome://inspect allows you to set breakpoints on statements within a line:

image

'"(Get-UICulture).TwoLetterISOLanguageName"';
try {
// If MUI != 'en' we'll ignore the content of the message
localeOk = execSync(powerShellFindMUI).toString('utf8').trim() === 'en';
Copy link
Member

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 =

Copy link
Contributor Author

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 🤔

Copy link
Member

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.

Copy link
Contributor Author

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 <tniessen@tnie.de>
@refack
Copy link
Contributor Author

refack commented Jun 5, 2017

Landed in 30a20bd

@refack refack merged commit 30a20bd into nodejs:master Jun 5, 2017
@refack refack deleted the test-module-mui-check branch June 5, 2017 21:25
jasnell pushed a commit that referenced this pull request Jun 7, 2017
PR-URL: #13393
Fixes: #13376
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x?

@refack
Copy link
Contributor Author

refack commented Jul 18, 2017

Yes. Does not land cleanly, I will backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. test Issues and PRs related to the tests. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test-module-loading-error fails on Windows with MUI set to a non-English language
7 participants