Skip to content

Commit

Permalink
src: update module version mismatch error message
Browse files Browse the repository at this point in the history
Fixes: #8379
PR-URL: #8391
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
jasnell committed Oct 10, 2016
1 parent 96b501d commit 1fda657
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/node.cc
Expand Up @@ -2406,8 +2406,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
char errmsg[1024];
snprintf(errmsg,
sizeof(errmsg),
"Module version mismatch. Expected %d, got %d.",
NODE_MODULE_VERSION, mp->nm_version);
"The module '%s'"
"\nwas compiled against a different Node.js version using"
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
"re-installing\nthe module (for instance, using `npm rebuild` or"
"`npm install`).",
*filename, mp->nm_version, NODE_MODULE_VERSION);

// NOTE: `mp` is allocated inside of the shared library's memory, calling
// `uv_dlclose` will deallocate it
Expand Down
15 changes: 15 additions & 0 deletions test/addons/node-module-version/binding.cc
@@ -0,0 +1,15 @@
#include <node_version.h>
#undef NODE_MODULE_VERSION
#define NODE_MODULE_VERSION 42
#include <node.h>

namespace {

inline void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
}

}

NODE_MODULE_CONTEXT_AWARE(binding, Initialize)
9 changes: 9 additions & 0 deletions test/addons/node-module-version/binding.gyp
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.cc' ]
}
]
}
11 changes: 11 additions & 0 deletions test/addons/node-module-version/test.js
@@ -0,0 +1,11 @@
'use strict';

require('../../common');
const assert = require('assert');

const re = new RegExp(
'was compiled against a different Node.js version using\n' +
'NODE_MODULE_VERSION 42. This version of Node.js requires\n' +
`NODE_MODULE_VERSION ${process.versions.modules}.`);

assert.throws(() => require('./build/Release/binding'), re);

0 comments on commit 1fda657

Please sign in to comment.