Skip to content

child_process execFile / spawn throw non-descript exception on windows if exe requires elevation #9464

Closed
@TanninOne

Description

@TanninOne
  • Version: v6.5.0
  • Platform: Windows 10 (x64)
  • Subsystem: child_process
let cp = require('child_process');
let util = require('util');
try {
  cp.execFileSync('SomeTool.exe')
} catch (err) {
  console.log('err', util.inspect(err));
}

outputs

err { Error: spawnSync SomeTool.exe UNKNOWN
    at exports._errnoException (util.js:1026:11)
    at spawnSync (child_process.js:461:20)
    at Object.execFileSync (child_process.js:498:13)
    at repl:2:4
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:313:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
  code: 'UNKNOWN',
  errno: 'UNKNOWN',
  ...
}

spawn generates the same error.

Obviously it would be better if this error was returned through the callback but I would also love to have a proper error code to react to the situation.
Not sure how execFile and spawn are implemented but it should be possible to report a proper errorcode as CreateProcess generates errorcode 740 if elevation is required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.libuvIssues and PRs related to the libuv dependency or the uv binding.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions