Skip to content

Commit 0614f87

Browse files
daveMuellerMarcoRossignoli
authored andcommitted
Improve exception message for sdk versions that doesn't support collectors (#569)
Improve exception message for sdk version that doesn't support collectors
1 parent 589e210 commit 0614f87

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,31 @@ private void OnSessionEnd(object sender, SessionEndEventArgs e)
165165
/// <returns>Test modules list</returns>
166166
private IEnumerable<string> GetTestModules(SessionStartEventArgs sessionStartEventArgs)
167167
{
168-
var testModules = sessionStartEventArgs.GetPropertyValue<IEnumerable<string>>(CoverletConstants.TestSourcesPropertyName);
169-
if (_eqtTrace.IsInfoEnabled)
168+
try
169+
{
170+
IEnumerable<string> testModules = GetPropertyValueWrapper(sessionStartEventArgs);
171+
if (_eqtTrace.IsInfoEnabled)
172+
{
173+
_eqtTrace.Info("{0}: TestModules: '{1}'",
174+
CoverletConstants.DataCollectorName,
175+
string.Join(",", testModules ?? Enumerable.Empty<string>()));
176+
}
177+
return testModules;
178+
}
179+
catch (MissingMethodException ex)
170180
{
171-
_eqtTrace.Info("{0}: TestModules: '{1}'",
172-
CoverletConstants.DataCollectorName,
173-
string.Join(",", testModules ?? Enumerable.Empty<string>()));
181+
throw new MissingMethodException("Make sure to use .NET core SDK Version >= 2.2.300", ex);
174182
}
183+
}
175184

176-
return testModules;
185+
/// <summary>
186+
/// Wraps GetPropertyValue to catch possible MissingMethodException on unsupported runtime
187+
/// </summary>
188+
/// <param name="sessionStartEventArgs"></param>
189+
/// <returns></returns>
190+
private static IEnumerable<string> GetPropertyValueWrapper(SessionStartEventArgs sessionStartEventArgs)
191+
{
192+
return sessionStartEventArgs.GetPropertyValue<IEnumerable<string>>(CoverletConstants.TestSourcesPropertyName);
177193
}
178194
}
179195
}

0 commit comments

Comments
 (0)