Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better error messages to insertion marker #4791

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions core/insertion_marker_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
Expand Down