From 2cfd62a229b0ca219877ef3fd8190420caf12e68 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Thu, 22 Apr 2021 11:13:09 -0700 Subject: [PATCH] Add better error messages to insertion marker (#4791) --- core/insertion_marker_manager.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index dc69e44df..79fee0a04 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -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()); } }