mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
Print a warning if JSON color value is invalid. (#1639)
Ignores the invalid color, defaulting to black.
This commit is contained in:
committed by
GitHub
parent
2358fe6fd5
commit
9cd6b1ec24
@@ -1054,6 +1054,7 @@ Blockly.Block.prototype.appendDummyInput = function(opt_name) {
|
||||
* @param {!Object} json Structured data describing the block.
|
||||
*/
|
||||
Blockly.Block.prototype.jsonInit = function(json) {
|
||||
var blockTypeName = json['type'];
|
||||
|
||||
// Validate inputs.
|
||||
goog.asserts.assert(
|
||||
@@ -1063,9 +1064,14 @@ Blockly.Block.prototype.jsonInit = function(json) {
|
||||
// Set basic properties of block.
|
||||
if (json['colour'] !== undefined) {
|
||||
var rawValue = json['colour'];
|
||||
var colour = goog.isString(rawValue) ?
|
||||
Blockly.utils.replaceMessageReferences(rawValue) : rawValue;
|
||||
this.setColour(colour);
|
||||
try {
|
||||
var colour = goog.isString(rawValue) ?
|
||||
Blockly.utils.replaceMessageReferences(rawValue) : rawValue;
|
||||
this.setColour(colour);
|
||||
} catch (colorError) {
|
||||
console.warn(
|
||||
'Block "' + blockTypeName + '": Illegal color value: ', rawValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Interpolate the message blocks.
|
||||
|
||||
Reference in New Issue
Block a user