File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
src/Cli/dotnet/Extensions Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -258,10 +258,20 @@ public static void HandleDebugSwitch(this ParseResult parseResult)
258
258
}
259
259
public static T ? SafelyGetValueForOption < T > ( this ParseResult parseResult , string name )
260
260
{
261
- if ( parseResult . GetResult ( name ) is OptionResult optionResult &&
262
- ! parseResult . Errors . Any ( e => e . SymbolResult == optionResult ) )
261
+ if ( parseResult . GetResult ( name ) is OptionResult optionResult && // only return a value if there _is_ a value - default or otherwise
262
+ ! parseResult . Errors . Any ( e => e . SymbolResult == optionResult ) // only return a value if this isn't a parsing error
263
+ && optionResult . Option . ValueType . IsAssignableTo ( typeof ( T ) ) ) // only return a value if coercing the type won't error
263
264
{
264
- return optionResult . GetValue < T > ( name ) ;
265
+ // shouldn't happen because of the above checks, but we can be safe since this is only used in telemetry, and should
266
+ // be resistant to errors
267
+ try
268
+ {
269
+ return optionResult . GetValue < T > ( name ) ;
270
+ }
271
+ catch
272
+ {
273
+ return default ;
274
+ }
265
275
}
266
276
else
267
277
{
You can’t perform that action at this time.
0 commit comments