mirror of https://github.com/nodejs/node.git
Make error reporting from node::DLOpen more consistent
parent
6ee73a2fee
commit
35f4182cee
25
src/node.cc
25
src/node.cc
|
@ -1461,7 +1461,9 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (args.Length() < 2) {
|
if (args.Length() < 2) {
|
||||||
return Undefined();
|
Local<Value> exception = Exception::Error(
|
||||||
|
String::New("process.dlopen takes exactly 2 arguments."));
|
||||||
|
return ThrowException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Utf8Value filename(args[0]->ToString()); // Cast
|
String::Utf8Value filename(args[0]->ToString()); // Cast
|
||||||
|
@ -1469,8 +1471,10 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
||||||
|
|
||||||
err = uv_dlopen(*filename, &lib);
|
err = uv_dlopen(*filename, &lib);
|
||||||
if (err.code != UV_OK) {
|
if (err.code != UV_OK) {
|
||||||
SetErrno(err);
|
Local<Value> exception = Exception::Error(
|
||||||
return scope.Close(Integer::New(-1));
|
String::Concat(String::New("Unable to load shared library "),
|
||||||
|
args[0]->ToString()));
|
||||||
|
return ThrowException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
String::Utf8Value path(args[0]->ToString());
|
String::Utf8Value path(args[0]->ToString());
|
||||||
|
@ -1501,9 +1505,9 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
||||||
/* Add the `_module` suffix to the extension name. */
|
/* Add the `_module` suffix to the extension name. */
|
||||||
r = snprintf(symbol, sizeof symbol, "%s_module", base);
|
r = snprintf(symbol, sizeof symbol, "%s_module", base);
|
||||||
if (r <= 0 || r >= sizeof symbol) {
|
if (r <= 0 || r >= sizeof symbol) {
|
||||||
err.code = UV_ENOMEM;
|
Local<Value> exception =
|
||||||
SetErrno(err);
|
Exception::Error(String::New("Out of memory."));
|
||||||
return scope.Close(Integer::New(-1));
|
return ThrowException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the init() function from the dynamically shared object.
|
// Get the init() function from the dynamically shared object.
|
||||||
|
@ -1520,15 +1524,16 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
|
||||||
err = uv_dlsym(lib, "init", reinterpret_cast<void**>(&mod->register_func));
|
err = uv_dlsym(lib, "init", reinterpret_cast<void**>(&mod->register_func));
|
||||||
if (err.code != UV_OK) {
|
if (err.code != UV_OK) {
|
||||||
uv_dlclose(lib);
|
uv_dlclose(lib);
|
||||||
SetErrno(err);
|
Local<Value> exception = Exception::Error(
|
||||||
return scope.Close(Integer::New(-1));
|
String::New("Out of memory."));
|
||||||
|
return ThrowException(exception);
|
||||||
}
|
}
|
||||||
/* End Compatibility hack */
|
/* End Compatibility hack */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mod->version != NODE_MODULE_VERSION) {
|
if (mod->version != NODE_MODULE_VERSION) {
|
||||||
Local<Value> exception =
|
Local<Value> exception = Exception::Error(
|
||||||
Exception::Error(String::New("Module version mismatch, refusing to load."));
|
String::New("Module version mismatch, refusing to load."));
|
||||||
return ThrowException(exception);
|
return ThrowException(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue