Skip to content

Commit

Permalink
Adjusting log message and add example
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisDyallo committed Aug 28, 2024
1 parent 9eacb29 commit e179465
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Yubico.YubiKey/src/Resources/ExceptionMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Yubico.YubiKey/src/Resources/ExceptionMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,6 @@
<value>The URI query cannot be null or empty.</value>
</data>
<data name="PivSessionDisposeUnknownError" xml:space="preserve">
<value>Unknown error when disposing PivSession</value>
<value>Exception caught when disposing PivSession: {0}, {1}</value>
</data>
</root>
12 changes: 10 additions & 2 deletions Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void Dispose()

// At the moment, there is no "close session" method. So for now,
// just connect to the management application.
// This can fail, so we wrap it in a try catch-block to complete the disposal of the PivSession
// This can fail, possibly resulting in a SCardException (or other), so we wrap it in a try catch-block to complete the disposal of the PivSession
try
{
_ = Connection.SendCommand(new SelectApplicationCommand(YubiKeyApplication.Management));
Expand All @@ -317,7 +317,15 @@ public void Dispose()
catch (Exception e)
#pragma warning restore CA1031
{
_log.LogWarning(e, ExceptionMessages.PivSessionDisposeUnknownError);
string message = string.Format(
CultureInfo.CurrentCulture,
ExceptionMessages.PivSessionDisposeUnknownError, e.GetType(), e.Message);

// Example:
// Exception caught when disposing PivSession: Yubico.PlatformInterop.SCardException,
// Unable to begin a transaction with the given smart card. SCARD_E_SERVICE_STOPPED: The smart card resource manager has shut down.

_log.LogWarning(message);
}

KeyCollector = null;
Expand Down

0 comments on commit e179465

Please sign in to comment.