diff --git a/src/cardreader.cpp b/src/cardreader.cpp index 8bfbdf9..61dc437 100644 --- a/src/cardreader.cpp +++ b/src/cardreader.cpp @@ -1,4 +1,5 @@ #include "cardreader.h" +#include "common.h" using namespace v8; using namespace node; @@ -334,7 +335,7 @@ void CardReader::HandleReaderStatusChange(uv_async_t *handle, int status) { NanCallback(NanNew(async_baton->callback)).Call(argc, argv); } else { - Local err = NanError(pcsc_stringify_error(ar->result)); + Local err = NanError(error_msg("SCardGetStatusChange", ar->result).c_str()); // Prepare the parameters for the callback function. const unsigned argc = 1; Handle argv[argc] = { err }; @@ -423,7 +424,7 @@ void CardReader::AfterConnect(uv_work_t* req, int status) { ConnectResult *cr = static_cast(baton->result); if (cr->result) { - Local err = NanError(pcsc_stringify_error(cr->result)); + Local err = NanError(error_msg("SCardConnect", cr->result).c_str()); // Prepare the parameters for the callback function. const unsigned argc = 1; Handle argv[argc] = { err }; @@ -477,7 +478,7 @@ void CardReader::AfterDisconnect(uv_work_t* req, int status) { LONG* result = reinterpret_cast(baton->result); if (*result) { - Local err = NanError(pcsc_stringify_error(*result)); + Local err = NanError(error_msg("SCardDisconnect", *result).c_str()); // Prepare the parameters for the callback function. const unsigned argc = 1; @@ -538,7 +539,7 @@ void CardReader::AfterTransmit(uv_work_t* req, int status) { TransmitResult *tr = static_cast(baton->result); if (tr->result) { - Local err = NanError(pcsc_stringify_error(tr->result)); + Local err = NanError(error_msg("SCardTransmit", tr->result).c_str()); // Prepare the parameters for the callback function. const unsigned argc = 1; @@ -602,7 +603,7 @@ void CardReader::AfterControl(uv_work_t* req, int status) { ControlResult *cr = static_cast(baton->result); if (cr->result) { - Local err = NanError(pcsc_stringify_error(cr->result)); + Local err = NanError(error_msg("SCardControl", cr->result).c_str()); // Prepare the parameters for the callback function. const unsigned argc = 1; diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..75f5a42 --- /dev/null +++ b/src/common.h @@ -0,0 +1,18 @@ +#ifndef COMMON_H +#define COMMON_H + +#define ERR_MSG_MAX_LEN 512 + +namespace { + std::string error_msg(const char* method, LONG result) { + char msg[ERR_MSG_MAX_LEN]; + snprintf(msg, + ERR_MSG_MAX_LEN, + "%s error: %s(0x%.8lx)", + method, + pcsc_stringify_error(result), result); + return msg; + } +} + +#endif /* COMMON_H */ diff --git a/src/pcsclite.cpp b/src/pcsclite.cpp index 3a6f0ce..f7cc18e 100644 --- a/src/pcsclite.cpp +++ b/src/pcsclite.cpp @@ -1,4 +1,5 @@ #include "pcsclite.h" +#include "common.h" using namespace v8; using namespace node; @@ -28,7 +29,7 @@ PCSCLite::PCSCLite(): m_card_context(NULL), NULL, &m_card_context); if (result != SCARD_S_SUCCESS) { - NanThrowError(pcsc_stringify_error(result)); + NanThrowError(error_msg("SCardEstablishContext", result).c_str()); } } @@ -102,7 +103,7 @@ void PCSCLite::HandleReaderStatusChange(uv_async_t *handle, int status) { NanCallback(NanNew(async_baton->callback)).Call(argc, argv); } else { - Local err = NanError(pcsc_stringify_error(ar->result)); + Local err = NanError(error_msg("SCardListReaders", ar->result).c_str()); // Prepare the parameters for the callback function. const unsigned argc = 1; Handle argv[argc] = { err };