Improving errors/warnings with Block.toDevString() and Connection.toString(). (#911)

This commit is contained in:
Andrew n marshall
2017-02-06 14:15:20 -08:00
committed by GitHub
parent 680fc4b6d3
commit 24ebbcaad0
3 changed files with 60 additions and 5 deletions

View File

@@ -1107,7 +1107,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
}
}
goog.asserts.assert(indexCount == args.length,
'Message does not reference all %s arg(s).', args.length);
'block "%s": Message does not reference all %s arg(s).', this.type, args.length);
// Add last dummy input if needed.
if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
goog.string.startsWith(elements[elements.length - 1]['type'],
@@ -1449,3 +1449,20 @@ Blockly.Block.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) {
return true;
};
/**
* This method returns a string describing this Block in developer terms (type
* name and ID; English only).
*
* Intended to on be used in console logs and errors. If you need a string that
* uses the user's native language (including block text, field values, and
* child blocks), use [toString()]{@link Blockly.Block#toString}.
* @return {string} The description.
*/
Blockly.Block.prototype.toDevString = function() {
var msg = this.type ? '"' + this.type + '" block' : 'Block';
if (this.id) {
msg += ' (id="' + this.id + '")';
}
return msg;
};