diff --git a/lib/gcli/languages/command.js b/lib/gcli/languages/command.js index f423a8e4..bc9f4381 100644 --- a/lib/gcli/languages/command.js +++ b/lib/gcli/languages/command.js @@ -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); if (isNew) { this.updateHints(); @@ -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(); diff --git a/lib/gcli/languages/languages.js b/lib/gcli/languages/languages.js index 49e0f1ec..738c7f94 100644 --- a/lib/gcli/languages/languages.js +++ b/lib/gcli/languages/languages.js @@ -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) { @@ -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) { @@ -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)); }, diff --git a/lib/gcli/ui/terminal.js b/lib/gcli/ui/terminal.js index fb2bbaa6..0c68e9a1 100644 --- a/lib/gcli/ui/terminal.js +++ b/lib/gcli/ui/terminal.js @@ -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); @@ -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); @@ -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; }; @@ -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 */