Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Make error reporting from node::DLOpen more consistent

  • Loading branch information...
piscisaureus committed Nov 4, 2011
1 parent 6ee73a2 commit 35f4182cee079e2c481dc436f5ea97966957def8
Showing with 15 additions and 10 deletions.
  1. +15 −10 src/node.cc
@@ -1461,16 +1461,20 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
int r;

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
Local<Object> target = args[1]->ToObject(); // Cast

err = uv_dlopen(*filename, &lib);
if (err.code != UV_OK) {
SetErrno(err);
return scope.Close(Integer::New(-1));
Local<Value> exception = Exception::Error(
String::Concat(String::New("Unable to load shared library "),
args[0]->ToString()));
return ThrowException(exception);
}

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. */
r = snprintf(symbol, sizeof symbol, "%s_module", base);
if (r <= 0 || r >= sizeof symbol) {
err.code = UV_ENOMEM;
SetErrno(err);
return scope.Close(Integer::New(-1));
Local<Value> exception =
Exception::Error(String::New("Out of memory."));
return ThrowException(exception);
}

// 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));
if (err.code != UV_OK) {
uv_dlclose(lib);
SetErrno(err);
return scope.Close(Integer::New(-1));
Local<Value> exception = Exception::Error(
String::New("Out of memory."));
return ThrowException(exception);
}
/* End Compatibility hack */
}

if (mod->version != NODE_MODULE_VERSION) {
Local<Value> exception =
Exception::Error(String::New("Module version mismatch, refusing to load."));
Local<Value> exception = Exception::Error(
String::New("Module version mismatch, refusing to load."));
return ThrowException(exception);
}

0 comments on commit 35f4182

Please sign in to comment.
You can’t perform that action at this time.