From 754fb4dc409b42a24910117c98f725a2ba63d21c Mon Sep 17 00:00:00 2001 From: Alexei Lozovsky Date: Sun, 7 Mar 2021 15:16:28 +0900 Subject: [PATCH] Detect and report vcvarsall.bat errors (#28) If the parameters passed to the script are incorrect -- for example, architecture is set to something the script does not understand -- then the script will print an error message *and* exit successfully without doing anything useful. Detect the error messages, forward them to the user, and fail the action. Hopefully, the information from the script will be enough to pinpoint the source of the issue. For example, if the action is run with: arch: Win32 then the output will be Found with vswhere: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat Error: [ERROR:vcvarsall.bat] Invalid argument found : Win32 Error: Could not setup Developer Command Prompt: invalid parameters which is close enough. --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index fec3981..47d142f 100644 --- a/index.js +++ b/index.js @@ -104,6 +104,24 @@ function main() { core.debug(`Running: ${command}`) const environment = child_process.execSync(command, {shell: "cmd"}).toString().split('\r\n') + // If vsvars.bat is given an incorrect command line, it will print out + // an error and *still* exit successfully. Parse out errors from output + // which don't look like environment variables, and fail if appropriate. + var failed = false + for (let line of environment) { + if (line.match(/^\[ERROR.*\]/)) { + failed = true + // Don't print this particular line which will be confusing in output. + if (line.match(/Error in script usage. The correct usage is:$/)) { + continue + } + core.error(line) + } + } + if (failed) { + throw new Error('invalid parameters') + } + for (let string of environment) { const [name, value] = string.split('=') for (let pattern of InterestingVariables) {