Commit b527e608 by Michael Mifsud

Improve error message for unsupported environments (#1491)

The human friendly name for an unknown platform, arch or runtime
is currently `false`. With this patch the user is better informed
as to why their environment is unsupported. The raw value is also
output to ease with bug reports.

Closes #1487
parent e232674d
...@@ -42,17 +42,30 @@ function getHumanNodeVersion(arg) { ...@@ -42,17 +42,30 @@ function getHumanNodeVersion(arg) {
} }
function getHumanEnvironment(env) { function getHumanEnvironment(env) {
var parts = env.replace(/_binding\.node$/, '').split('-'); var binding = env.replace(/_binding\.node$/, ''),
parts = binding.split('-'),
platform = getHumanPlatform(parts[0]),
arch = getHumanArchitecture(parts[1]),
runtime = getHumanNodeVersion(parts[2]);
if (parts.length !== 3) { if (parts.length !== 3) {
return 'Unknown environment'; return 'Unknown environment (' + binding + ')';
}
if (!platform) {
platform = 'Unsupported platform (' + parts[0] + ')';
}
if (!arch) {
arch = 'Unsupported architecture (' + parts[1] + ')';
}
if (!runtime) {
runtime = 'Unsupported runtime (' + parts[2] + ')';
} }
return [ return [
getHumanPlatform(parts[0]), platform, arch, 'with', runtime,
getHumanArchitecture(parts[1]),
'with',
getHumanNodeVersion(parts[2]),
].join(' '); ].join(' ');
} }
...@@ -60,11 +73,11 @@ function getInstalledBinaries() { ...@@ -60,11 +73,11 @@ function getInstalledBinaries() {
return fs.readdirSync(defaultBinaryPath); return fs.readdirSync(defaultBinaryPath);
} }
function isSupportedEnvironment() { function isSupportedEnvironment(platform, arch, runtime) {
return ( return (
false !== getHumanPlatform() && false !== getHumanPlatform(platform) &&
false !== getHumanArchitecture() && false !== getHumanArchitecture(arch) &&
false !== getHumanNodeVersion() false !== getHumanNodeVersion(runtime)
); );
} }
......
...@@ -1829,49 +1829,94 @@ describe('api', function() { ...@@ -1829,49 +1829,94 @@ describe('api', function() {
}); });
describe('on unsupported environment', function() { describe('on unsupported environment', function() {
it('should error for unsupported architecture', function() { describe('with an unsupported architecture', function() {
var prevValue = process.arch; var prevValue;
beforeEach(function() {
prevValue = process.arch;
Object.defineProperty(process, 'arch', { Object.defineProperty(process, 'arch', {
get: function () { return 'foo'; } get: function () { return 'foo'; }
}); });
});
afterEach(function() {
process.arch = prevValue;
});
it('should error', function() {
assert.throws( assert.throws(
function() { require(sassPath); }, function() { require(sassPath); },
'Node Sass does not yet support your current environment' 'Node Sass does not yet support your current environment'
); );
});
process.arch = prevValue; it('should inform the user the architecture is unsupported', function() {
assert.throws(
function() { require(sassPath); },
'Unsupported architecture (foo)'
);
});
}); });
it('should error for unsupported platform', function() { describe.only('with an unsupported platform', function() {
var prevValue = process.platform; var prevValue;
beforeEach(function() {
prevValue = process.platform;
Object.defineProperty(process, 'platform', { Object.defineProperty(process, 'platform', {
get: function () { return 'foo'; } get: function () { return 'bar'; }
});
});
afterEach(function() {
process.platform = prevValue;
}); });
it('should error', function() {
assert.throws( assert.throws(
function() { require(sassPath); }, function() { require(sassPath); },
'Node Sass does not yet support your current environment' 'Node Sass does not yet support your current environment'
); );
});
process.platform = prevValue; it('should inform the user the platform is unsupported', function() {
assert.throws(
function() { require(sassPath); },
'Unsupported platform (bar)'
);
}); });
});
describe('with an unsupported platform', function() {
var prevValue;
it('should error for unsupported runtime', function() { beforeEach(function() {
var prevValue = process.versions.modules; prevValue = process.versions.modules;
Object.defineProperty(process.versions, 'modules', { Object.defineProperty(process.versions, 'modules', {
get: function () { return 'foo'; } get: function () { return 'baz'; }
});
}); });
afterEach(function() {
process.versions.modules = prevValue;
});
it('should error', function() {
assert.throws( assert.throws(
function() { require(sassPath); }, function() { require(sassPath); },
'Node Sass does not yet support your current environment' 'Node Sass does not yet support your current environment'
); );
});
process.versions.modules = prevValue; it('should inform the user the runtime is unsupported', function() {
assert.throws(
function() { require(sassPath); },
'Unsupported runtime (baz)'
);
});
}); });
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment