amaiorano created this revision. amaiorano added reviewers: klimek, hans, zturner. amaiorano added a subscriber: cfe-commits.
When clang-format outputs to stderr but returns 0, the extension will format the code anyway. This happens, for instance, when there's a syntax error or unknown value in a .clang-format file; the result is that the extension silently formats using the fallback style without informing the user of the problem. This change treats stderr output as an error, making sure it gets displayed to the user, and not formatting the code. https://reviews.llvm.org/D27440 Files: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs Index: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs =================================================================== --- tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs +++ tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs @@ -295,12 +295,18 @@ string output = process.StandardOutput.ReadToEnd(); // 5. clang-format is done, wait until it is fully shut down. process.WaitForExit(); - if (process.ExitCode != 0) + + // FIXME: If clang-format writes enough to the standard error stream to block, + // we will never reach this point; instead, read the standard error asynchronously. + string stdErr = process.StandardError.ReadToEnd(); + + if (process.ExitCode != 0 || stdErr.Length > 0) { - // FIXME: If clang-format writes enough to the standard error stream to block, - // we will never reach this point; instead, read the standard error asynchronously. - throw new Exception(process.StandardError.ReadToEnd()); + throw new Exception( + (stdErr.Length > 0 ? stdErr + "\n\n" : "") + + "(Exit Code: " + process.ExitCode + ")"); } + return output; }
Index: tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs =================================================================== --- tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs +++ tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs @@ -295,12 +295,18 @@ string output = process.StandardOutput.ReadToEnd(); // 5. clang-format is done, wait until it is fully shut down. process.WaitForExit(); - if (process.ExitCode != 0) + + // FIXME: If clang-format writes enough to the standard error stream to block, + // we will never reach this point; instead, read the standard error asynchronously. + string stdErr = process.StandardError.ReadToEnd(); + + if (process.ExitCode != 0 || stdErr.Length > 0) { - // FIXME: If clang-format writes enough to the standard error stream to block, - // we will never reach this point; instead, read the standard error asynchronously. - throw new Exception(process.StandardError.ReadToEnd()); + throw new Exception( + (stdErr.Length > 0 ? stdErr + "\n\n" : "") + + "(Exit Code: " + process.ExitCode + ")"); } + return output; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits