Skip to content
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

fix docker compile err #29

Closed
33 changes: 22 additions & 11 deletions src/disruptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ class Disruptor : public Napi::ObjectWrap<Disruptor>
Napi::Value GetPendingSeqNextEnd(const Napi::CallbackInfo& info);
Napi::Value GetAllConsumersIgnoring(const Napi::CallbackInfo& info);

// ignore coverage
void ThrowErrnoError(const Napi::CallbackInfo& info,
const char *msg);
const char *msg) __attribute__((no_instrument_function));
};

//LCOV_EXCL_START
Expand Down Expand Up @@ -422,23 +423,33 @@ class CloseFD
}
};

// Exclude err_to_string from code coverage analysis
static std::string err_to_string(int errmsg) __attribute__((unused, no_instrument_function));
static std::string err_to_string(int errmsg) {
return std::to_string(errmsg);
}

static std::string err_to_string(char* errmsg) __attribute__((unused, no_instrument_function));
static std::string err_to_string(char* errmsg) {
return std::string(errmsg);
}

void Disruptor::ThrowErrnoError(const Napi::CallbackInfo& info,
const char *msg)
{
int errnum = errno;
char buf[1024] = {0};
#ifdef __APPLE__
auto err = strerror_r(errnum, buf, sizeof(buf));
static_assert(std::is_same<decltype(err), int>::value,
"strerror_r must return int");
char *errmsg = err == 0 ? buf : nullptr;
#else
auto errmsg = strerror_r(errnum, buf, sizeof(buf));
static_assert(std::is_same<decltype(errmsg), char*>::value,
"strerror_r must return char*");
#endif
throw Napi::Error::New(info.Env(),

if (std::is_same<decltype(err), int>::value) {
char *errmsg = (err == 0) ? buf : nullptr;
throw Napi::Error::New(info.Env(),
std::string(msg) + ": " + (errmsg ? errmsg : std::to_string(errnum)));
} else {
auto errmsg = strerror_r(errnum, buf, sizeof(buf));
throw Napi::Error::New(info.Env(),
std::string(msg) + ": " + (errmsg ? err_to_string(errmsg) : std::to_string(errnum)));
}
}

Disruptor::Disruptor(const Napi::CallbackInfo& info) :
Expand Down
Loading