Skip to content

Commit

Permalink
Updated the torch install error message when no internet. Fixes #986 (#…
Browse files Browse the repository at this point in the history
…987)

* Updated the torch install error message when no internet. Fixes #986

* WIP #986 removed extra console log
  • Loading branch information
brollb authored Mar 12, 2017
1 parent 4ca379f commit 71d79a6
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions bin/deepforge
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,34 @@ var installTorch = function() {
args = `clone https://github.com/torch/distro.git ${tgtDir} --recursive`.split(' ');

return spawn('git', args)
.then(code => {
if (code !== 0) {
if (code === 128) {
console.error(`${tgtDir} is not empty. ` +
'Please empty it or change the torch directory:\n' +
'\n deepforge config torch.dir NEW/TORCH/PATH\n');
.catch(result => {
var error = result.error || result.stderr ||
`Torch install failed with exit code ${result.code}`;

if (result.stderr.includes('unable to access')) {
error = `Could not access the torch repository. Are you ` +
`connected to the internet?\n`;
} else if (result.code === 128) {
error = `${tgtDir} is not empty. ` +
'Please empty it or change the torch directory:\n' +
'\n deepforge config torch.dir NEW/TORCH/PATH\n';

}

throw `Torch install Failed with exit code ${code}`;
} else { // continue installation
process.chdir(tgtDir);
return spawn('bash', ['install-deps'])
.then(() => spawn('bash', ['install.sh'], true))
.then(() => {
storeConfig('torch.dir', tgtDir);
console.log('Installed torch. Please close and ' +
're-open your terminal to use DeepForge w/ ' +
'torch support!');
process.exit(0);
});
}

console.error(error);
process.exit(result.code);
})
.then((code, stderr) => {
process.chdir(tgtDir);
return spawn('bash', ['install-deps'])
.then(() => spawn('bash', ['install.sh'], true))
.then(() => {
storeConfig('torch.dir', tgtDir);
console.log('Installed torch. Please close and ' +
're-open your terminal to use DeepForge w/ ' +
'torch support!');
process.exit(0);
});
});
} else {
return Q();
Expand All @@ -243,21 +249,32 @@ var spawn = function(cmd, args, opts) {
spawnOpts = typeof opts === 'object' ? opts : null,
forwardStdin = opts === true,
isOpen = true,
stderr = '',
err;

args = args || [];
job = spawnOpts ? rawSpawn(cmd, args, spawnOpts) : rawSpawn(cmd, args);
job.stdout.on('data', data => process.stdout.write(data));
job.stderr.on('data', data => process.stderr.write(data));
job.stderr.on('data', data => {
stderr += data;
process.stderr.write(data);
});

job.on('close', code => {
isOpen = false;
if (err) {
deferred.reject(err, code);
if (err || code !== 0) {
deferred.reject({
code: code,
stderr: stderr,
error: err
});
} else {
deferred.resolve(code);
}
});
job.on('error', e => err = e);
job.on('error', e => {
err = e;
});

if (forwardStdin) {
process.stdin.on('data', data => {
Expand Down

0 comments on commit 71d79a6

Please sign in to comment.