Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 8787be3

Browse files
committed
feat(error-handling): add ScardCardCommunicationFailedError and map more error codes for improved error handling
Signed-off-by: Mart Somermaa <[email protected]>
1 parent 6f4498b commit 8787be3

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

.github/workflows/codeql-analysis.yml renamed to .github/temporarily-disabled-workflows/codeql-analysis.yml

File renamed without changes.

include/pcsc-cpp/pcsc-cpp-utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inline std::string int2hexstr(const T value)
4141
return hexStringBuilder.str();
4242
}
4343

44-
/** Remove absolute path prefix until "src" from the given path, '/path/to/src/main.cpp' becomes
44+
/** Remove absolute path prefix until 'src' from the given path, '/path/to/src/main.cpp' becomes
4545
* 'src/main.cpp'. */
4646
inline std::string removeAbsolutePathPrefix(const std::string& filePath)
4747
{

include/pcsc-cpp/pcsc-cpp.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ class ScardNoCardError : public ScardError
352352
using ScardError::ScardError;
353353
};
354354

355+
/** Thrown when communication with the card or reader fails. */
356+
class ScardCardCommunicationFailedError : public ScardError
357+
{
358+
public:
359+
using ScardError::ScardError;
360+
};
361+
355362
/** Thrown when the card is removed from the selected reader. */
356363
class ScardCardRemovedError : public ScardError
357364
{

src/SCardCall.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,17 @@ void SCardCall(const char* callerFunctionName, const char* file, int line,
5454
throw ScardServiceNotRunningError(
5555
buildErrorMessage(callerFunctionName, scardFunctionName, result, file, line));
5656
case SCARD_E_NO_READERS_AVAILABLE:
57+
case SCARD_E_READER_UNAVAILABLE:
5758
throw ScardNoReadersError(
5859
buildErrorMessage(callerFunctionName, scardFunctionName, result, file, line));
5960
case SCARD_E_NO_SMARTCARD:
6061
throw ScardNoCardError(
6162
buildErrorMessage(callerFunctionName, scardFunctionName, result, file, line));
63+
case SCARD_E_NOT_READY:
64+
case SCARD_E_INVALID_VALUE:
65+
case SCARD_E_COMM_DATA_LOST:
66+
throw ScardCardCommunicationFailedError(
67+
buildErrorMessage(callerFunctionName, scardFunctionName, result, file, line));
6268
case SCARD_W_REMOVED_CARD:
6369
throw ScardCardRemovedError(
6470
buildErrorMessage(callerFunctionName, scardFunctionName, result, file, line));

0 commit comments

Comments
 (0)