[PATCH] D27440: clang-format-vsix: fail when clang-format outputs to stderr

Antonio Maiorano via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 5 17:41:37 PST 2016


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;
         }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27440.80359.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161206/d5dfaed1/attachment.bin>


More information about the cfe-commits mailing list