From 5ceafda3a426afe8274a4917ddf3ad77f41ea2c4 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 26 Oct 2020 14:09:11 +0100 Subject: [PATCH 1/2] vstest.console: CommandLineOptions: preserve stacktrace on re-throw (CA2200) --- src/vstest.console/CommandLine/CommandLineOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs index 64d212043b..9c25faf8eb 100644 --- a/src/vstest.console/CommandLine/CommandLineOptions.cs +++ b/src/vstest.console/CommandLine/CommandLineOptions.cs @@ -295,14 +295,14 @@ public void AddSource(string source) // Get matching files from file pattern parser matchingFiles = FilePatternParser.GetMatchingFiles(source); } - catch(TestSourceException ex) + catch(TestSourceException) { if(source.StartsWith("-") || source.StartsWith("/")) { throw new TestSourceException( string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidArgument, source)); } - throw ex; + throw; } // Add the matching files to source list this.sources = this.sources.Union(matchingFiles).ToList(); From 5e422a362e4bef13517c45a6ceb379bcbd21cd94 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Tue, 26 Jan 2021 13:22:47 +0100 Subject: [PATCH 2/2] PR feedback --- src/vstest.console/CommandLine/CommandLineOptions.cs | 10 +++------- .../CommandLine/TestSourceException.cs | 12 +++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs index 9c25faf8eb..4edd13929b 100644 --- a/src/vstest.console/CommandLine/CommandLineOptions.cs +++ b/src/vstest.console/CommandLine/CommandLineOptions.cs @@ -295,14 +295,10 @@ public void AddSource(string source) // Get matching files from file pattern parser matchingFiles = FilePatternParser.GetMatchingFiles(source); } - catch(TestSourceException) + catch(TestSourceException ex) when (source.StartsWith("-") || source.StartsWith("/")) { - if(source.StartsWith("-") || source.StartsWith("/")) - { - throw new TestSourceException( - string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidArgument, source)); - } - throw; + throw new TestSourceException( + string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidArgument, source), ex); } // Add the matching files to source list this.sources = this.sources.Union(matchingFiles).ToList(); diff --git a/src/vstest.console/CommandLine/TestSourceException.cs b/src/vstest.console/CommandLine/TestSourceException.cs index 0cb6903b17..05f5e734f2 100644 --- a/src/vstest.console/CommandLine/TestSourceException.cs +++ b/src/vstest.console/CommandLine/TestSourceException.cs @@ -25,7 +25,17 @@ public TestSourceException() /// /// Message for the exception. public TestSourceException(string message) - : base(message) + : this(message, innerException: null) + { + } + + /// + /// Initializes with the message and innerException. + /// + /// Message for the exception. + /// The exception that is the cause of the current exception, or a null reference. + public TestSourceException(string message, Exception innerException) + : base(message, innerException) { }