@@ -18,29 +18,50 @@ public static Exception CreateKVCException(string msg, Exception ex, Configurati
1818 // level.
1919 if ( ex is ConfigurationErrorsException ceex )
2020 {
21- var inner = new KeyValueConfigException ( $ "'{ cb . Name } ' { msg } ==> { ceex . InnerException ? . Message ?? ceex . Message } ", ex . InnerException ) ;
22- return new KeyValueConfigWrappedException ( ceex . Message , inner ) ;
21+ var inner = new KeyValueConfigBuilderException ( $ "'{ cb . Name } ' { msg } ==> { ceex . InnerException ? . Message ?? ceex . Message } ", ex . InnerException ) ;
22+ return new KeyValueConfigurationErrorsException ( ceex . Message , inner ) ;
2323 }
2424
25- return new KeyValueConfigException ( $ "'{ cb . Name } ' { msg } : { ex . Message } ", ex ) ;
25+ var ff = new KeyValueConfigBuilderException ( ) ;
26+ return new KeyValueConfigBuilderException ( $ "'{ cb . Name } ' { msg } : { ex . Message } ", ex ) ;
2627 }
2728
28- public static bool IsKeyValueConfigException ( Exception ex ) => ( ex is KeyValueConfigException ) || ( ex is KeyValueConfigWrappedException ) ;
29+ // We only want to wrap the original exception. Once we wrap it, just keep raising the wrapped
30+ // exception so we don't create an endless chain of exception wrappings that are not helpful when
31+ // being surfaced in a YSOD or similar. Use this helper to determine if wrapping is needed.
32+ public static bool IsKeyValueConfigException ( Exception ex ) => ( ex is KeyValueConfigBuilderException ) || ( ex is KeyValueConfigurationErrorsException ) ;
2933 }
3034
3135 // There are two different exception types here because the .Net config system treats
3236 // ConfigurationErrorsExceptions differently. It considers it to be a pre-wrapped and ready for
33- // presentation exception. Other exceptions get wrapped by the config system.
37+ // presentation exception. Other exceptions get wrapped by the config system. We don't want
38+ // to lose that "pre-wrapped-ness" if the exception has already been through .Net config.
3439
40+ /// <summary>
41+ /// An exception that wraps the root failure due to non-config exceptions while processing Key Value Config Builders.
42+ /// </summary>
3543 [ Serializable ]
36- internal class KeyValueConfigException : Exception
44+ public class KeyValueConfigBuilderException : Exception
3745 {
38- public KeyValueConfigException ( string msg , Exception inner ) : base ( msg , inner ) { }
46+ /// <summary>
47+ /// Initializes a new instance of the <see cref="KeyValueConfigBuilderException"/> class.
48+ /// </summary>
49+ public KeyValueConfigBuilderException ( ) : base ( ) { }
50+
51+ internal KeyValueConfigBuilderException ( string msg , Exception inner ) : base ( msg , inner ) { }
3952 }
4053
54+ /// <summary>
55+ /// An exception that wraps the root failure due to config exceptions while processing Key Value Config Builders.
56+ /// </summary>
4157 [ Serializable ]
42- internal class KeyValueConfigWrappedException : ConfigurationErrorsException
58+ public class KeyValueConfigurationErrorsException : ConfigurationErrorsException
4359 {
44- public KeyValueConfigWrappedException ( string msg , Exception inner ) : base ( msg , inner ) { }
60+ /// <summary>
61+ /// Initializes a new instance of the <see cref="KeyValueConfigurationErrorsException"/> class.
62+ /// </summary>
63+ public KeyValueConfigurationErrorsException ( ) : base ( ) { }
64+
65+ internal KeyValueConfigurationErrorsException ( string msg , Exception inner ) : base ( msg , inner ) { }
4566 }
4667}
0 commit comments