镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Read a stored value its SemanticString type refuses as not found [patch] - #217

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/216-invalid-semantic-string-reads-as-not-found
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/216-invalid-semantic-string-reads-as-not-found

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #216

What changed

CredentialSerialization.Deserialize and DeserializeFromString now also catch ArgumentException and return null. A SemanticString<T> property's round-trip converter builds its value through the validating factory, which throws ArgumentException when the stored value fails validation. That exception used to escape both methods and CredentialCache.TryGet.

So an entry that is damaged, was written by another tool, or was saved before a type's validation got stricter now reads as "not found", the same as any other unreadable entry. The app can then ask for the credential again instead of throwing on every TryGet.

Tests

InvalidStoredValueTests (next to UnknownPayloadTests) registers a credential with an [IsBase64] SemanticString and plants {"$type":...,"Token":"not base64!"}:

  • Deserialize and DeserializeFromString return null, and TryGet returns false. Without the fix, all three fail with ArgumentException: Cannot convert "not base64!" to Base64Token.
  • A valid stored value still reads back.

Full suite: 107 passed, 5 skipped (native-store and Windows-only tests), 0 failed.


Generated by Claude Code

CredentialSerialization.Deserialize and DeserializeFromString now catch
ArgumentException, which a SemanticString property's validating factory
throws for a value it refuses. A damaged entry, one another tool wrote,
or one saved before a type's validation was tightened now makes TryGet
return false instead of throwing, like any other unreadable entry.

Fixes #216

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW6R8MN1ipg19Mih4Z3
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TryGet throws ArgumentException instead of returning false when a stored value fails a custom subclass's SemanticString validation

2 participants