|  | 
| 22 | 22 | 'use strict'; | 
| 23 | 23 | const common = require('../common'); | 
| 24 | 24 | const assert = require('assert'); | 
|  | 25 | +const { execSync } = require('child_process'); | 
| 25 | 26 | 
 | 
| 26 |  | -const error_desc = { | 
|  | 27 | +const errorMessagesByPlatform = { | 
| 27 | 28 |   win32: ['%1 is not a valid Win32 application'], | 
| 28 | 29 |   linux: ['file too short', 'Exec format error'], | 
| 29 | 30 |   sunos: ['unknown file type', 'not an ELF file'], | 
| 30 | 31 |   darwin: ['file too short'] | 
| 31 | 32 | }; | 
| 32 |  | -const dlerror_msg = error_desc[process.platform]; | 
|  | 33 | +// If we don't know a priori what the error would be, we accept anything. | 
|  | 34 | +const errorMessages = errorMessagesByPlatform[process.platform] || ['']; | 
|  | 35 | + | 
|  | 36 | +// On Windows, error messages are MUI dependent | 
|  | 37 | +// Ref: https://github.com/nodejs/node/issues/13376 | 
|  | 38 | +let localeOk = true; | 
|  | 39 | +if (common.isWindows) { | 
|  | 40 | +  const powerShellFindMUI = | 
|  | 41 | +    'powershell -NoProfile -ExecutionPolicy Unrestricted -c ' + | 
|  | 42 | +    '"(Get-UICulture).TwoLetterISOLanguageName"'; | 
|  | 43 | +  try { | 
|  | 44 | +    // If MUI != 'en' we'll ignore the content of the message | 
|  | 45 | +    localeOk = execSync(powerShellFindMUI).toString('utf8').trim() === 'en'; | 
|  | 46 | +  } catch (_) { | 
|  | 47 | +    // It's only a best effort try to find the MUI | 
|  | 48 | +  } | 
|  | 49 | +} | 
| 33 | 50 | 
 | 
| 34 | 51 | assert.throws( | 
| 35 | 52 |   () => { require('../fixtures/module-loading-error.node'); }, | 
| 36 | 53 |   (e) => { | 
| 37 |  | -    if (dlerror_msg && !dlerror_msg.some((msg) => e.message.includes(msg))) | 
| 38 |  | -      return false; | 
| 39 |  | -    if (e.name !== 'Error') | 
|  | 54 | +    if (localeOk && !errorMessages.some((msg) => e.message.includes(msg))) | 
| 40 | 55 |       return false; | 
| 41 |  | -    return true; | 
|  | 56 | +    return e.name === 'Error'; | 
| 42 | 57 |   } | 
| 43 | 58 | ); | 
| 44 | 59 | 
 | 
|  | 
0 commit comments