Add better error messages to insertion marker (#4791)

This commit is contained in:
Beka Westberg
2021-04-22 11:13:09 -07:00
committed by GitHub
parent f2f878db8c
commit 2cfd62a229

View File

@@ -148,6 +148,17 @@ Blockly.InsertionMarkerManager.PREVIEW_TYPE = {
REPLACEMENT_FADE: 2,
};
/**
* An error message to throw if the block created by createMarkerBlock_ is
* missing any components.
* @type {string}
* @const
*/
Blockly.InsertionMarkerManager.DUPLICATE_BLOCK_ERROR = 'The insertion marker ' +
'manager tried to create a marker but the result is missing %1. If ' +
'you are using a mutator, make sure your domToMutation method is ' +
'properly defined.';
/**
* Sever all links from this object.
* @package
@@ -279,9 +290,17 @@ Blockly.InsertionMarkerManager.prototype.createMarkerBlock_ = function(sourceBlo
continue; // Ignore the collapsed input.
}
var resultInput = result.inputList[i];
if (!resultInput) {
throw new Error(Blockly.InsertionMarkerManager.DUPLICATE_BLOCK_ERROR
.replace('%1', 'an input'));
}
for (var j = 0; j < sourceInput.fieldRow.length; j++) {
var sourceField = sourceInput.fieldRow[j];
var resultField = resultInput.fieldRow[j];
if (!resultField) {
throw new Error(Blockly.InsertionMarkerManager.DUPLICATE_BLOCK_ERROR
.replace('%1', 'a field'));
}
resultField.setValue(sourceField.getValue());
}
}