Add a public exception hierarchy (C2) - #28
Merged
Conversation
The library's exceptions derived straight from Exception with no common base,
so consumers couldn't catch (SimpleSettingsException); four were internal yet
escaped the public build path (uncatchable by type); context lived only in
message strings; and the reachable not-an-interface guard threw an untyped
InvalidOperationException.
- New public abstract SimpleSettingsException : Exception (protected (message)
and (message, inner) ctors; no parameterless or [Serializable] ctor -
BinaryFormatter is obsolete on the net8/net10 targets). All 10 library
exceptions now derive from it.
- Promote the four build-path escapees to public: SettingsPropertyValueException,
SettingsPropertyNullException, TypeGenerationException,
SettingsPropertyExtractionException.
- Flatten three mis-namespaced types to the root namespace so the public
surface is coherent: SettingsExtractionException (was .Core),
TypeGenerationException and SettingsPropertyExtractionException
(were .Core.Reflection).
- Expose leak-safe structured properties instead of forcing consumers to parse
messages: SettingsBindingException.{BinderType,Section,Key};
SettingsPropertyValueException.{SettingsType,PropertyName,TargetType,
ConversionErrorType}; SettingsType / OptionType / ArgumentName on the rest.
- Replace the untyped InvalidOperationException(TypeIsNotInterface) throws with
a typed SettingsTypeNotInterfaceException (the one runtime-behavior break -
see release notes). The two documented-unreachable "No converter found"
InvalidOperationExceptions are left as internal invariant guards.
S1 secret-redaction is now structural, not conventional:
SettingsPropertyValueException's ctor takes the failure's Type (not the
Exception), so a value-bearing object cannot cross its boundary; and
SettingsBindingException stores primitives instead of retaining the
BindingContext, which holds the bound value.
Reviewed: plan by security-auditor + dotnet-architect (both
ENDORSE-WITH-CHANGES; adopted the Type-not-Exception hardening, namespace
flattening, Section/ConversionErrorType naming, and reflection-based
accessibility tests since InternalsVisibleTo masks it); code by /code-review
plus Roslyn detect_antipatterns (0).
Tests: SimpleSettings/ExceptionHierarchyTests.cs (+6) - base is public+abstract,
a reflection invariant that every library exception derives from the base, the
four promotions are public, non-interface -> typed + catchable as base,
conversion failure -> structured metadata + InnerException == null, and
binder-throws -> binder context. The existing not-interface test updated to the
new type. Suite 82 net10 (was 76).
Also refreshes FIX-PLAN.md (C2 marked done, stale "bare Exception" line fixed)
and SESSION-HANDOFF.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
C2 — public exception hierarchy
The library's 10 exceptions derived straight from
Exceptionwith no common base (consumers couldn'tcatch (SimpleSettingsException)); 4 wereinternalyet escaped the public build path (uncatchable by type); context lived only in message strings; and the reachable not-an-interface guard threw an untypedInvalidOperationException.Changes
public abstract class SimpleSettingsException : Exception— protected(message)+(message, inner)ctors (no parameterless/[Serializable]ctor; BinaryFormatter is obsolete on net8/net10). All 10 exceptions reparented →catch (SimpleSettingsException)catches the family.SettingsPropertyValueException,SettingsPropertyNullException,TypeGenerationException,SettingsPropertyExtractionException.SettingsExtractionException(was.Core),TypeGenerationException+SettingsPropertyExtractionException(were.Core.Reflection).SettingsBindingException.{BinderType,Section,Key},SettingsPropertyValueException.{SettingsType,PropertyName,TargetType,ConversionErrorType}, andSettingsType/OptionType/ArgumentNameon the rest.SettingsTypeNotInterfaceExceptionreplaces theInvalidOperationException(TypeIsNotInterface)throws. The two documented-unreachable "No converter found"InvalidOperationExceptions are left as internal invariant guards.S1 redaction is now structural (not conventional)
SettingsPropertyValueException's ctor takes the failure'sType(not theException), so a value-bearing object can't cross its boundary — andInnerExceptionstaysnull(asserted by test).SettingsBindingExceptionstores primitives instead of retaining theBindingContext(which holds the bound value).Breaking
Pre-stable, so mostly free. The one real runtime break: a non-interface type now throws
SettingsTypeNotInterfaceExceptioninstead ofInvalidOperationException. Reparenting and namespace moves are source-compatible forcatchof the concrete types orException; internal→public is additive. Release-note the not-interface change.Tests (+6, suite 82 net10)
SimpleSettings/ExceptionHierarchyTests.cs: base is public+abstract; a reflection invariant that every library exception derives from the base (fails if a future exception isn't reparented); the 4 promotions arepublic(via reflection —InternalsVisibleTomasks it from a plain reference); not-interface→typed+catchable-as-base; conversion→structured metadata +InnerException == null; binder-throws→context. Existing not-interface test updated to the new type.Review
security-auditor(ENDORSE-WITH-CHANGES — no leak reopened; adopted theType-not-Exceptionhardening) anddotnet-architect(ENDORSE-WITH-CHANGES — namespace flatten,Section/ConversionErrorTypenaming, reflection-based accessibility tests)./code-review(high) + Roslyndetect_antipatterns(0). Build clean, both TFMs.Follows #27 (S1).