Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
runat-1128988: Use .catch(...) in place of .then(null, ...)
Browse files Browse the repository at this point in the history
I thought that catch() died with end(), but apparently not. This has the
downside that Eclipse/JSDT mistakes the function 'catch' for the keyword
of the same name, so all parsing fails, but I don't think we should hold
back code for the sake of broken editors.

Signed-off-by: Joe Walker <[email protected]>
  • Loading branch information
joewalker committed Mar 5, 2015
1 parent cd39f73 commit 969e9da
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 23 deletions.
8 changes: 3 additions & 5 deletions gcli.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function logResults(output) {
requisition.updateExec(command)
.then(logResults)
.then(extraActions)
.then(null, util.errorHandler);
.catch(util.errorHandler);

/**
* Start a NodeJS REPL to execute commands
Expand All @@ -96,10 +96,8 @@ function startRepl() {
if (command.length !== 0) {
requisition.updateExec(command)
.then(logResults)
.then(
function() { callback(); },
function(ex) { util.errorHandler(ex); callback(); }
);
.then(function() { callback(); })
.catch(function(ex) { util.errorHandler(ex); callback(); });
}
};

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
gcli.createTerminal(system).then(function(terminal) {
terminal.language.showIntro(); // Intro text
test.run(terminal, false); // Run the unit test at each startup
}).then(null, console.error.bind(console));
}).catch(console.error.bind(console));
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion lib/gcli/commands/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ var xhrsocket = {
res.status(500).send(text);
};

return Promise.resolve(reply).then(onResolve).then(null, onReject);
return Promise.resolve(reply).then(onResolve).catch(onReject);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/gcli/fields/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SelectionField.prototype.setConversion = function(conversion) {
prediction;
}, this);
this.menu.show(items, conversion.arg.text);
}.bind(this), util.errorHandler);
}.bind(this)).catch(util.errorHandler);
};

SelectionField.prototype.itemClicked = function(ev) {
Expand All @@ -85,7 +85,7 @@ SelectionField.prototype.itemClicked = function(ev) {
this.type.parse(arg, context).then(function(conversion) {
this.onFieldChange({ conversion: conversion });
this.setMessage(conversion.message);
}.bind(this)).then(null, util.errorHandler);
}.bind(this)).catch(util.errorHandler);
};

SelectionField.prototype.getConversion = function() {
Expand Down
6 changes: 3 additions & 3 deletions lib/gcli/languages/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var commandLanguage = exports.commandLanguage = {
var isNew = (this.assignment !== newAssignment);

this.assignment = newAssignment;
this.terminal.updateCompletion().then(null, util.errorHandler);
this.terminal.updateCompletion().catch(util.errorHandler);

if (isNew) {
this.updateHints();
Expand Down Expand Up @@ -286,7 +286,7 @@ var commandLanguage = exports.commandLanguage = {
}

this.terminal.history.add(input);
this.terminal.unsetChoice().then(null, util.errorHandler);
this.terminal.unsetChoice().catch(util.errorHandler);

this.terminal.inputElement.value = '';
this.terminal_previousValue = this.terminal.inputElement.value;
Expand Down Expand Up @@ -499,7 +499,7 @@ var commandLanguage = exports.commandLanguage = {
this.terminal.scrollToBottom();
data.throbEle.style.display = ev.output.completed ? 'none' : 'block';
}.bind(this));
}.bind(this)).then(null, console.error);
}.bind(this)).catch(console.error);

this.terminal.addElement(data.rowinEle);
this.terminal.addElement(data.rowoutEle);
Expand Down
2 changes: 1 addition & 1 deletion lib/gcli/languages/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var baseLanguage = {

this.focusManager.outputted();

this.terminal.unsetChoice().then(null, util.errorHandler);
this.terminal.unsetChoice().catch(util.errorHandler);
this.terminal.inputElement.value = '';
}.bind(this));
},
Expand Down
4 changes: 2 additions & 2 deletions lib/gcli/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ exports.createSystem = function(options) {
pendingChanges = true;
}
else {
loadModule(name).then(null, console.error);
loadModule(name).catch(console.error);
}
});
},
Expand Down Expand Up @@ -252,7 +252,7 @@ exports.createSystem = function(options) {
*/
exports.connectFront = function(system, front, customProps) {
front.on('commandsChanged', function(specs) {
syncItems(system, front, customProps).then(null, util.errorHandler);
syncItems(system, front, customProps).catch(util.errorHandler);
});

return syncItems(system, front, customProps);
Expand Down
2 changes: 1 addition & 1 deletion lib/gcli/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ exports.run = function(terminal, isRemote) {
console.log(helpers.timingSummary);
document.testStatus = examiner.status.name;

setMocks(options, false).then(closeIfPhantomJs).then(null, function(ex) {
setMocks(options, false).then(closeIfPhantomJs).catch(function(ex) {
console.error(ex);
closeIfPhantomJs();
});
Expand Down
6 changes: 3 additions & 3 deletions lib/gcli/ui/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Terminal.prototype._updateLanguage = function(language) {
}

this.language.updateHints();
this.updateCompletion().then(null, util.errorHandler);
this.updateCompletion().catch(util.errorHandler);
this.promptElement.innerHTML = this.language.prompt;
};

Expand Down Expand Up @@ -393,7 +393,7 @@ Terminal.prototype.onKeyDown = function(ev) {
* if something went wrong.
*/
Terminal.prototype.onKeyUp = function(ev) {
this.handleKeyUp(ev).then(null, util.errorHandler);
this.handleKeyUp(ev).catch(util.errorHandler);
};

/**
Expand Down Expand Up @@ -590,7 +590,7 @@ Terminal.prototype.updateCompletion = function() {
* event handlers that can't react to rejected promises.
*/
Terminal.prototype._updateCompletionWithErrorHandler = function() {
this.updateCompletion().then(null, util.errorHandler);
this.updateCompletion().catch(util.errorHandler);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/gcli/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ exports.promiseEach = function(array, action, scope) {
};

var reply = action.call(scope, array[index], index, array);
Promise.resolve(reply).then(onSuccess).then(null, onFailure);
Promise.resolve(reply).then(onSuccess).catch(onFailure);
};

callNext(0);
Expand Down
2 changes: 1 addition & 1 deletion remote.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
gcli.createTerminal(system).then(function(terminal) {
test.run(terminal, true);
});
}).then(null, console.error.bind(console));
}).catch(console.error.bind(console));
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion web/gcli/types/fileparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports.parse = function(context, typed, options) {
return Promise.resolve(reply.predictions);
};
}
front.connection.disconnect().then(null, util.errorHandler);
front.connection.disconnect().catch(util.errorHandler);
return reply;
});
});
Expand Down
2 changes: 1 addition & 1 deletion web/gcli/util/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.spawn = function(context, spawnSpec) {
var connector = context.system.connectors.get();
return GcliFront.create(connector).then(function(front) {
return front.system(cmd, cleanArgs, cwd, cleanEnv).then(function(reply) {
front.connection.disconnect().then(null, util.errorHandler);
front.connection.disconnect().catch(util.errorHandler);
return reply;
});
});
Expand Down

1 comment on commit 969e9da

@bgrins
Copy link

@bgrins bgrins commented on 969e9da Mar 19, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.