warn user if attempting to download package without internet connection

This commit is contained in:
Iuri Matias 2017-12-16 17:05:37 -05:00
parent b764ecf4d6
commit f90321a23e
4 changed files with 23 additions and 15 deletions

View File

@ -81,8 +81,8 @@ class Compiler {
}
self.logger.info("loading solc compiler..");
solcW.load_compiler(function () {
callback();
solcW.load_compiler(function (err) {
callback(err);
});
},
function compileContracts(callback) {

View File

@ -29,7 +29,10 @@ class SolcW {
solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'});
} else {
let npm = new Npm({logger: this.logger});
npm.getPackageVersion('solc', this.solcVersion, false, false, function(location) {
npm.getPackageVersion('solc', this.solcVersion, false, false, function(err, location) {
if (err) {
return done(err);
}
let requirePath = path.join(process.env.PWD, location);
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
});

View File

@ -24,9 +24,9 @@ class Npm {
if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) {
if (returnContent) {
let distFile = packageDirectory + packageName + ".js";
callback(fs.readFileSync(distFile).toString());
callback(null, fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
callback(null, packageDirectory);
}
} else {
fs.mkdirpSync(packageDirectory);
@ -36,9 +36,9 @@ class Npm {
utils.extractTar(packageDirectory + "/" + packageName + ".js", packageDirectory, function() {
if (returnContent) {
let distFile = packageDirectory + packageName + ".js";
callback(fs.readFileSync(distFile).toString());
callback(null, fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
callback(null, packageDirectory);
}
});
});
@ -52,9 +52,9 @@ class Npm {
if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) {
if (returnContent) {
let distFile = packageDirectory + returnContent;
callback(fs.readFileSync(distFile).toString());
callback(null, fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
callback(null, packageDirectory);
}
} else {
fs.mkdirpSync(packageDirectory);
@ -64,9 +64,9 @@ class Npm {
utils.extractTar(packageDirectory + "/downloaded_package.tgz", packageDirectory, function() {
if (returnContent) {
let distFile = packageDirectory + returnContent;
callback(fs.readFileSync(distFile).toString());
callback(null, fs.readFileSync(distFile).toString());
} else {
callback(packageDirectory);
callback(null, packageDirectory);
}
});
});
@ -78,7 +78,13 @@ class Npm {
let self = this;
let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version;
utils.httpsGet(npmRegistry, function (_err, body) {
utils.httpsGet(npmRegistry, function (err, body) {
if (err) {
if (err.code === 'ENOTFOUND') {
return callback("can't reach " + err.hostname + " to download " + packageName + " " + version + " - are you connected to the internet?");
}
return callback(err);
}
let registryJSON = JSON.parse(body);
if (getFromGit) {

View File

@ -42,9 +42,8 @@ function httpGetRequest(httpObj, url, callback) {
res.on('end', function () {
callback(null, body);
});
res.on('error', function (err) {
callback(err);
});
}).on('error', function (err) {
callback(err);
});
}