From 12d7d645dd0466d19e61b9a4ac69653b8f4a9817 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Fri, 25 Oct 2019 14:52:13 -0700 Subject: [PATCH] src: add file name to 'Module did not self-register' error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/30125 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: David Carlier Reviewed-By: Tobias Nießen --- src/node_binding.cc | 7 ++++++- test/addons/dlopen-ping-pong/test-worker.js | 3 ++- test/addons/dlopen-ping-pong/test.js | 2 +- test/addons/not-a-binding/test.js | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/node_binding.cc b/src/node_binding.cc index 3a5ea646fc68d8..4adb4b893925b1 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -485,7 +485,12 @@ void DLOpen(const FunctionCallbackInfo& args) { mp = dlib->GetSavedModuleFromGlobalHandleMap(); if (mp == nullptr || mp->nm_context_register_func == nullptr) { dlib->Close(); - env->ThrowError("Module did not self-register."); + char errmsg[1024]; + snprintf(errmsg, + sizeof(errmsg), + "Module did not self-register: '%s'.", + *filename); + env->ThrowError(errmsg); return false; } } diff --git a/test/addons/dlopen-ping-pong/test-worker.js b/test/addons/dlopen-ping-pong/test-worker.js index feba6aa5eb0202..d24bd2df8050f2 100644 --- a/test/addons/dlopen-ping-pong/test-worker.js +++ b/test/addons/dlopen-ping-pong/test-worker.js @@ -16,5 +16,6 @@ require(bindingPath); new Worker(`require(${JSON.stringify(bindingPath)})`, { eval: true }) .on('error', common.mustCall((err) => { assert.strictEqual(err.constructor, Error); - assert.strictEqual(err.message, 'Module did not self-register.'); + assert.strictEqual(err.message, + `Module did not self-register: '${bindingPath}'.`); })); diff --git a/test/addons/dlopen-ping-pong/test.js b/test/addons/dlopen-ping-pong/test.js index c5b8c16493f60f..c3461d8bd269c5 100644 --- a/test/addons/dlopen-ping-pong/test.js +++ b/test/addons/dlopen-ping-pong/test.js @@ -19,5 +19,5 @@ assert.strictEqual(module.exports.ping(), 'pong'); // Check that after the addon is loaded with // process.dlopen() a require() call fails. console.log('require:', `./build/${common.buildType}/binding`); -const re = /^Error: Module did not self-register\.$/; +const re = /^Error: Module did not self-register: '.*[\\/]binding\.node'\.$/; assert.throws(() => require(`./build/${common.buildType}/binding`), re); diff --git a/test/addons/not-a-binding/test.js b/test/addons/not-a-binding/test.js index a0ce2d0629ac1d..4b4e7150ebbca2 100644 --- a/test/addons/not-a-binding/test.js +++ b/test/addons/not-a-binding/test.js @@ -2,5 +2,5 @@ const common = require('../../common'); const assert = require('assert'); -const re = /^Error: Module did not self-register\.$/; +const re = /^Error: Module did not self-register: '.*[\\/]binding\.node'\.$/; assert.throws(() => require(`./build/${common.buildType}/binding`), re);