This repository has been archived by the owner on Feb 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Failed error check in download callback #18
Comments
Yes! I'm having the same problem :/ I use "scp" and have a block that says something like "if scp returns an err, print it and callback", but the function keeps going instead of exiting and is causing node to crash. If I give it a hostname that works, this code works great! But if the path doesn't exist, it fails with:
I'll insert more code: scp.scp({
host: 'somehost',
username: 'myusername',
password: 'mypassword',
path: 'somepath'
}, './', function(err) {
console.log(err);
callback(err); //the code doesn't stop here, though!
}); I was able to fix this by changing this code: Client.prototype.download = function(src, dest, callback) {
var self = this;
self.sftp(function(err,sftp){
var sftp_readStream = sftp.createReadStream(src);
sftp_readStream.on('error', function(err){
callback(err);
});
sftp_readStream.pipe(fs.createWriteStream(dest))
.on('close',function(){
self.emit('read', src);
callback(null);
})
.on('error', function(err){
callback(err);
});
});
}; to this: Client.prototype.download = function(src, dest, callback) {
var self = this;
self.sftp(function(err,sftp){
if(!err) //<---
{ //<---
var sftp_readStream = sftp.createReadStream(src);
sftp_readStream.on('error', function(err){
callback(err);
});
sftp_readStream.pipe(fs.createWriteStream(dest))
.on('close',function(){
self.emit('read', src);
callback(null);
})
.on('error', function(err){
callback(err);
});
}else //<---
{ //<---
callback(err); //<---
} //<---
});
}; I'll fork the repo and do a pull request |
KSoto
added a commit
to KSoto/node-scp2
that referenced
this issue
May 20, 2015
Fixing this issue: spmjs#18 If there is an error in the download function, it would break when trying to use "sftp". This fixes that.
This was referenced May 20, 2015
lepture
pushed a commit
that referenced
this issue
Jun 1, 2015
Fixing this issue: #18 If there is an error in the download function, it would break when trying to use "sftp". This fixes that.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
https://github.com/lepture/node-scp2/blob/master/lib/client.js#L281
Error is never checked, and instead assumes sftp will always be defined. In cases where an error has occurred, a
TypeError: Cannot call method 'createReadStream' of undefined
is thrownThe text was updated successfully, but these errors were encountered: