teambition / gulp-ssh

SSH and SFTP tasks for gulp
184 stars 38 forks source link

Add proper error callback on connect #10

Closed dimw closed 9 years ago

dimw commented 9 years ago

Currently, the gulp task ends in undefined state when connecting to a non-existing server or with wrong credentials. Instead, an error event should be fired to allow proper error handling.

gulpfile.js for testing:

var gulp = require('gulp');
var GulpSSH = require('gulp-ssh');

gulp.task('default', function (completed) {
    var gulpSSH = new GulpSSH({
        ignoreErrors: false,
        sshConfig: {
            host: 'example.com',
            port: 22,
            username: 'root',
            password: ''
        }
    });

    return gulpSSH
        .exec(['uptime'])
        .on('error', function (err) {
            completed('Completed with errors!');
        })
        .on('end', function(){
            completed();
        });
});
zensh commented 9 years ago
var gulp = require('gulp');
var GulpSSH = require('gulp-ssh');

gulp.task('default', function (completed) {
    var gulpSSH = new GulpSSH({
        ignoreErrors: false,
        sshConfig: {
            host: 'example.com',
            port: 22,
            username: 'root',
            password: ''
        }
    });

   gulpSSH
        .on('error', function (err) {
            completed('Completed with errors!');
        })
        .on('end', function(){
            completed();
        });

    return gulpSSH
        .exec(['uptime']);
});