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

Commit

Permalink
runat-1128988: Report rejected promises
Browse files Browse the repository at this point in the history
Chance some places where promises were being dropped on the floor.

Signed-off-by: Joe Walker <[email protected]>
  • Loading branch information
joewalker committed Feb 5, 2015
1 parent 8246a77 commit f525d59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 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();
this.terminal.updateCompletion().then(null, util.errorHandler);

This comment has been minimized.

Copy link
@bgrins

bgrins Feb 24, 2015

Nit: You can just use catch() for this pattern

This comment has been minimized.

Copy link
@joewalker

joewalker Mar 5, 2015

Author Owner

So you can. I thought that catch() died with done(), but apparently not.


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

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

return this.requisition.exec().then(function() {
this.textChanged();
Expand Down
12 changes: 7 additions & 5 deletions lib/gcli/languages/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ var baseLanguage = {
},

handleTab: function() {
this.terminal.unsetChoice();
return RESOLVED;
return this.terminal.unsetChoice().then(function() {
return RESOLVED;
}, util.errorHandler);
},

handleInput: function(input) {
Expand All @@ -62,8 +63,9 @@ var baseLanguage = {
}.bind(this));
}

this.terminal.unsetChoice();
return RESOLVED;
return this.terminal.unsetChoice().then(function() {
return RESOLVED;
}, util.errorHandler);
},

handleReturn: function(input) {
Expand All @@ -80,7 +82,7 @@ var baseLanguage = {

this.focusManager.outputted();

this.terminal.unsetChoice();
this.terminal.unsetChoice().then(null, util.errorHandler);
this.terminal.inputElement.value = '';
}.bind(this));
},
Expand Down
14 changes: 11 additions & 3 deletions lib/gcli/ui/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Terminal.prototype._init = function(system, options, terminalCss, terminalHtml)
this.focusManager.addMonitoredElement(this.tooltipElement, 'tooltip');
this.focusManager.addMonitoredElement(this.inputElement, 'input');

this.onInputChange.add(this.updateCompletion, this);
this.onInputChange.add(this._updateCompletionWithErrorHandler, this);

host.script.onOutput.add(this.onOutput);

Expand Down Expand Up @@ -185,7 +185,7 @@ Terminal.prototype.destroy = function() {
this.field.onFieldChange.remove(this.fieldChanged, this);
this.field.destroy();

this.onInputChange.remove(this.updateCompletion, this);
this.onInputChange.remove(this._updateCompletionWithErrorHandler, this);

// Remove the output elements so they free the event handers
util.clearElement(this.displayElement);
Expand Down Expand Up @@ -265,7 +265,7 @@ Terminal.prototype._updateLanguage = function(language) {
}

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

Expand Down Expand Up @@ -584,6 +584,14 @@ Terminal.prototype.updateCompletion = function() {
}.bind(this));
};

/**
* Call updateCompletion, but log if something is wrong. To be called by
* event handlers that can't react to rejected promises.
*/
Terminal.prototype._updateCompletionWithErrorHandler = function() {
this.updateCompletion().then(null, util.errorHandler);
};

/**
* The terminal acts on UP/DOWN if there is a menu showing
*/
Expand Down

1 comment on commit f525d59

@bgrins
Copy link

@bgrins bgrins commented on f525d59 Feb 24, 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.