-
Notifications
You must be signed in to change notification settings - Fork 438
Added ArgumentNullException type with ValidationError #2818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iNinja
merged 6 commits into
dev
from
iinglese/argumentnullexception-with-validationerror
Sep 13, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18de458
Added SecurityTokenArgumentNullException. Added interface to align sy…
iNinja d8d28e2
Added missing documentation
iNinja d871edb
Removed code used to highlight how Nullables work during a call
iNinja 42bdb96
Fixed typo
iNinja 981b4b8
Merge branch 'dev' into iinglese/argumentnullexception-with-validatio…
iNinja e44243b
Added missing documentation
iNinja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
src/Microsoft.IdentityModel.Tokens/Exceptions/SecurityTokenArgumentNullException.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| #if !NET8_0_OR_GREATER | ||
| using System.Text; | ||
| #endif | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Microsoft.IdentityModel.Tokens | ||
| { | ||
| internal class SecurityTokenArgumentNullException : ArgumentNullException, ISecurityTokenException | ||
| { | ||
| private string? _stackTrace; | ||
| private ValidationError? _validationError; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SecurityTokenArgumentNullException"/> class. | ||
| /// </summary> | ||
| public SecurityTokenArgumentNullException() | ||
| : base() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SecurityTokenArgumentNullException"/> class with a specified null parameter. | ||
| /// </summary> | ||
| /// <param name="paramName">The name of the null parameter that triggered the exception.</param> | ||
| public SecurityTokenArgumentNullException(string? paramName) | ||
| : base(paramName) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SecurityTokenArgumentNullException"/> class with a specified error message | ||
| /// and a reference to the inner exception that is the cause of this exception. | ||
| /// </summary> | ||
| /// <param name="message">The error message that explains the reason for the exception.</param> | ||
| /// <param name="innerException">The <see cref="Exception"/> that is the cause of the current exception, or a null reference if no inner exception is specified.</param> | ||
| public SecurityTokenArgumentNullException(string? message, Exception? innerException) | ||
| : base(message, innerException) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SecurityTokenArgumentNullException"/> class with a specified null parameter and an error message. | ||
| /// </summary> | ||
| /// <param name="paramName">The name of the null parameter that triggered the exception.</param> | ||
| /// <param name="message">The error message that explains the reason for the exception.</param> | ||
| public SecurityTokenArgumentNullException(string? paramName, string? message) | ||
| : base(paramName, message) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets the <see cref="ValidationError"/> that is associated with the exception. | ||
| /// </summary> | ||
| /// <param name="validationError">The validation error to associate with the exception.</param> | ||
| public void SetValidationError(ValidationError validationError) | ||
| { | ||
| _validationError = validationError; | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Gets the stack trace that is captured when the exception is created. | ||
| /// </summary> | ||
| public override string? StackTrace | ||
| { | ||
| get | ||
| { | ||
| if (_stackTrace == null) | ||
| { | ||
| if (_validationError == null) | ||
| return base.StackTrace; | ||
| #if NET8_0_OR_GREATER | ||
| _stackTrace = new StackTrace(_validationError.StackFrames).ToString(); | ||
| #else | ||
| StringBuilder sb = new(); | ||
| foreach (StackFrame frame in _validationError.StackFrames) | ||
| { | ||
| sb.Append(frame.ToString()); | ||
| sb.Append(Environment.NewLine); | ||
| } | ||
|
|
||
| _stackTrace = sb.ToString(); | ||
| #endif | ||
| } | ||
|
|
||
| return _stackTrace; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| #nullable restore |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.