diff options
author | Brett Vickers <brett@beevik.com> | 2019-08-20 21:53:13 (GMT) |
---|---|---|
committer | Brett Vickers <brett@beevik.com> | 2019-08-28 00:09:47 (GMT) |
commit | 3242c794fa408737d9d24290b543b4e5db5dbdde (patch) | |
tree | c9000565801c1d618683813e7f25212a4cede63c /src/subprocess-win32.cc | |
parent | ae3130c9bc25079b4b51a92c6c784673c82fc0cd (diff) | |
download | Ninja-3242c794fa408737d9d24290b543b4e5db5dbdde.zip Ninja-3242c794fa408737d9d24290b543b4e5db5dbdde.tar.gz Ninja-3242c794fa408737d9d24290b543b4e5db5dbdde.tar.bz2 |
Improve error messages when ninja commands fail on Windows.
When a call to the Win32 API CreateProcessA fails, ninja
now outputs the exact command string that caused it to fail.
It also detects when the command contained leading whitespace
and outputs a hint that lets the user know why the command
failed.
Diffstat (limited to 'src/subprocess-win32.cc')
-rw-r--r-- | src/subprocess-win32.cc | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/subprocess-win32.cc b/src/subprocess-win32.cc index a4a7669..d221476 100644 --- a/src/subprocess-win32.cc +++ b/src/subprocess-win32.cc @@ -124,12 +124,20 @@ bool Subprocess::Start(SubprocessSet* set, const string& command) { buf_ = "CreateProcess failed: The system cannot find the file " "specified.\n"; return true; - } else if (error == ERROR_INVALID_PARAMETER) { - // This generally means that the command line was too long. Give extra - // context for this case. - Win32Fatal("CreateProcess", "is the command line too long?"); } else { - Win32Fatal("CreateProcess"); // pass all other errors to Win32Fatal + fprintf(stderr, "\nCreateProcess failed. Command attempted:\n\"%s\"\n", + command.c_str()); + const char* hint = NULL; + // ERROR_INVALID_PARAMETER means the command line was formatted + // incorrectly. This can be caused by a command line being too long or + // leading whitespace in the command. Give extra context for this case. + if (error == ERROR_INVALID_PARAMETER) { + if (command.length() > 0 && (command[0] == ' ' || command[0] == '\t')) + hint = "command contains leading whitespace"; + else + hint = "is the command line too long?"; + } + Win32Fatal("CreateProcess", hint); } } |