From b6eb4649917f4e9051a94427096d08a388f1edc0 Mon Sep 17 00:00:00 2001 From: Anton Wilhelm Date: Mon, 7 Dec 2015 13:38:16 +0100 Subject: [PATCH] better error handling, fix #20 - provide error handling for callback - provide default error handling if no callback is passed --- lib/index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index df5b3e3..4a190ca 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,14 +48,27 @@ function getRepo(options) { * Push a git branch to a remote (pushes gh-pages by default). * @param {string} basePath The base path. * @param {Object} config Publish options. - * @param {Function} done Callback. + * @param {Function} callback Callback. */ -exports.publish = function publish(basePath, config, done) { + /*eslint-disable no-console */ +exports.publish = function publish(basePath, config, callback) { if (typeof config === 'function') { - done = config; + callback = config; config = {}; } + var done = function(arguments) { + try { + (callback || function(err) { + if (!err) { + console.log(err) + } + })(arguments); + } catch (err) { + console.error('errors during calling the callback: ', err); + } + } + var defaults = { add: false, git: 'git',