@@ -324,70 +324,84 @@ private bool ParseSettingValueBoolean(object value, string settingName)
324
324
325
325
private void ParseSettingsHashtable ( Hashtable settings )
326
326
{
327
+ IList < Exception > exceptions = new List < Exception > ( ) ;
328
+
327
329
ISet < string > uniqueSettingKeys = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
328
330
foreach ( DictionaryEntry setting in settings )
329
331
{
330
332
if ( setting . Key is null )
331
333
{
332
- throw new InvalidDataException ( Strings . SettingKeyIsNull ) ;
334
+ exceptions . Add ( new InvalidDataException (
335
+ Strings . SettingKeyIsNull ) ) ;
336
+ continue ;
333
337
}
334
338
335
339
if ( ! ( setting . Key is string ) )
336
340
{
337
- throw new InvalidDataException ( string . Format (
341
+ exceptions . Add ( new InvalidDataException ( string . Format (
338
342
Strings . SettingKeyIsNotStringType ,
339
- setting . Key ) ) ;
343
+ setting . Key ) ) ) ;
344
+ continue ;
340
345
}
341
346
string settingName = setting . Key as string ;
342
347
343
348
if ( ! uniqueSettingKeys . Add ( settingName ) )
344
349
{
345
350
// setting.Key should be used instead of settingName because the former preserves information about the source casing.
346
- throw new InvalidDataException ( string . Format (
351
+ exceptions . Add ( new InvalidDataException ( string . Format (
347
352
Strings . SettingKeyIsNotUniqueIgnoringCase ,
348
- setting . Key ) ) ;
353
+ setting . Key ) ) ) ;
354
+ continue ;
349
355
}
350
356
351
357
if ( setting . Value is null )
352
358
{
353
- throw new InvalidDataException ( string . Format (
359
+ exceptions . Add ( new InvalidDataException ( string . Format (
354
360
Strings . SettingValueIsNull ,
355
- settingName ) ) ;
361
+ settingName ) ) ) ;
362
+ continue ;
356
363
}
357
364
358
365
// ToLowerInvariant is important to also work with turkish culture, see https://github.com/PowerShell/PSScriptAnalyzer/issues/1095
359
366
switch ( settingName . ToLowerInvariant ( ) )
360
367
{
361
368
case "severity" :
369
+ // TODO Aggregate exceptions.
362
370
this . severities = ParseSettingValueStringOrStrings ( setting . Value , settingName ) ;
363
371
break ;
364
372
365
373
case "includerules" :
374
+ // TODO Aggregate exceptions.
366
375
this . includeRules = ParseSettingValueStringOrStrings ( setting . Value , settingName ) ;
367
376
break ;
368
377
369
378
case "excluderules" :
379
+ // TODO Aggregate exceptions.
370
380
this . excludeRules = ParseSettingValueStringOrStrings ( setting . Value , settingName ) ;
371
381
break ;
372
382
373
383
case "customrulepath" :
384
+ // TODO Aggregate exceptions.
374
385
this . customRulePath = ParseSettingValueStringOrStrings ( setting . Value , settingName ) ;
375
386
break ;
376
387
377
388
case "includedefaultrules" :
389
+ // TODO Aggregate exceptions.
378
390
this . includeDefaultRules = ParseSettingValueBoolean ( setting . Value , settingName ) ;
379
391
break ;
380
392
381
393
case "recursecustomrulepath" :
394
+ // TODO Aggregate exceptions.
382
395
this . recurseCustomRulePath = ParseSettingValueBoolean ( setting . Value , settingName ) ;
383
396
break ;
384
397
385
398
case "rules" :
386
399
if ( ! ( setting . Value is System . Collections . IDictionary ) )
387
400
{
388
- throw new InvalidDataException ( string . Format (
401
+ exceptions . Add ( new InvalidDataException ( string . Format (
389
402
Strings . SettingRulesValueIsNotDictionaryType ,
390
- setting . Value ) ) ;
403
+ setting . Value ) ) ) ;
404
+ continue ;
391
405
}
392
406
Hashtable rules = setting . Value as Hashtable ;
393
407
@@ -397,38 +411,44 @@ private void ParseSettingsHashtable(Hashtable settings)
397
411
{
398
412
if ( rule . Key is null )
399
413
{
400
- throw new InvalidDataException ( Strings . SettingRuleKeyIsNull ) ;
414
+ exceptions . Add ( new InvalidDataException (
415
+ Strings . SettingRuleKeyIsNull ) ) ;
416
+ continue ;
401
417
}
402
418
403
419
if ( ! ( rule . Key is string ) )
404
420
{
405
- throw new InvalidDataException ( string . Format (
421
+ exceptions . Add ( new InvalidDataException ( string . Format (
406
422
Strings . SettingRuleKeyIsNotStringType ,
407
- rule . Key ) ) ;
423
+ rule . Key ) ) ) ;
424
+ continue ;
408
425
}
409
426
string ruleName = rule . Key as string ;
410
427
411
428
if ( ! uniqueRuleKeys . Add ( ruleName ) )
412
429
{
413
430
// rule.Key should be used instead of ruleName because the former preserves information about the source casing.
414
- throw new InvalidDataException ( string . Format (
431
+ exceptions . Add ( new InvalidDataException ( string . Format (
415
432
Strings . SettingRuleKeyIsNotUniqueIgnoringCase ,
416
- rule . Key ) ) ;
433
+ rule . Key ) ) ) ;
434
+ continue ;
417
435
}
418
436
419
437
if ( rule . Value is null )
420
438
{
421
- throw new InvalidDataException ( string . Format (
439
+ exceptions . Add ( new InvalidDataException ( string . Format (
422
440
Strings . SettingRuleValueIsNull ,
423
- ruleName ) ) ;
441
+ ruleName ) ) ) ;
442
+ continue ;
424
443
}
425
444
426
445
if ( ! ( rule . Value is System . Collections . IDictionary ) )
427
446
{
428
- throw new InvalidDataException ( string . Format (
447
+ exceptions . Add ( new InvalidDataException ( string . Format (
429
448
Strings . SettingRuleValueIsNotDictionaryType ,
430
449
ruleName ,
431
- rule . Value ) ) ;
450
+ rule . Value ) ) ) ;
451
+ continue ;
432
452
}
433
453
Hashtable arguments = rule . Value as Hashtable ;
434
454
@@ -438,35 +458,39 @@ private void ParseSettingsHashtable(Hashtable settings)
438
458
{
439
459
if ( argument . Key is null )
440
460
{
441
- throw new InvalidDataException ( string . Format (
461
+ exceptions . Add ( new InvalidDataException ( string . Format (
442
462
Strings . SettingRuleArgumentKeyIsNull ,
443
- ruleName ) ) ;
463
+ ruleName ) ) ) ;
464
+ continue ;
444
465
}
445
466
446
467
if ( ! ( argument . Key is string ) )
447
468
{
448
- throw new InvalidDataException ( string . Format (
469
+ exceptions . Add ( new InvalidDataException ( string . Format (
449
470
Strings . SettingRuleArgumentKeyIsNotStringType ,
450
471
ruleName ,
451
- argument . Key ) ) ;
472
+ argument . Key ) ) ) ;
473
+ continue ;
452
474
}
453
475
string argumentName = argument . Key as string ;
454
476
455
477
if ( ! uniqueArgumentKeys . Add ( argumentName ) )
456
478
{
457
479
// argument.Key should be used instead of argumentName because the former preserves information about the source casing.
458
- throw new InvalidDataException ( string . Format (
480
+ exceptions . Add ( new InvalidDataException ( string . Format (
459
481
Strings . SettingRuleArgumentKeyIsNotUniqueIgnoringCase ,
460
482
ruleName ,
461
- argument . Key ) ) ;
483
+ argument . Key ) ) ) ;
484
+ continue ;
462
485
}
463
486
464
487
if ( argument . Value is null )
465
488
{
466
- throw new InvalidDataException ( string . Format (
489
+ exceptions . Add ( new InvalidDataException ( string . Format (
467
490
Strings . SettingRuleArgumentValueIsNull ,
468
491
ruleName ,
469
- argumentName ) ) ;
492
+ argumentName ) ) ) ;
493
+ continue ;
470
494
}
471
495
472
496
parsedArguments [ argumentName ] = argument . Value ;
@@ -479,11 +503,17 @@ private void ParseSettingsHashtable(Hashtable settings)
479
503
break ;
480
504
481
505
default :
482
- throw new InvalidDataException ( string . Format (
506
+ exceptions . Add ( new InvalidDataException ( string . Format (
483
507
Strings . WrongKeyHashTable ,
484
- settingName ) ) ;
508
+ settingName ) ) ) ;
509
+ continue ;
485
510
}
486
511
}
512
+
513
+ if ( exceptions . Count > 0 )
514
+ {
515
+ throw new AggregateException ( exceptions ) ;
516
+ }
487
517
}
488
518
489
519
private void ParseSettingsFile ( string settingsFilePath )
0 commit comments