Skip to content

Insertion marker throws unclear error when mutations are badly defined #4485

@BeksOmega

Description

@BeksOmega

Describe the bug

If your mutator's domToMutation method is not properly defined it can cause insertion markers to throw the following error when you drag the mutated block:

core.js:6241 ERROR TypeError: Cannot read property 'fieldRow' of undefined
    at Blockly.InsertionMarkerManager.createMarkerBlock_ (blockly_compressed.js:304)
    at new Blockly.InsertionMarkerManager (blockly_compressed.js:299)
    at new Blockly.BlockDragger (blockly_compressed.js:318)
    at Blockly.TouchGesture.Blockly.Gesture.startDraggingBlock_ (blockly_compressed.js:443)
    at Blockly.TouchGesture.Blockly.Gesture.updateIsDraggingBlock_ (blockly_compressed.js:440)
    at Blockly.TouchGesture.Blockly.Gesture.updateIsDragging_ (blockly_compressed.js:442)
    at Blockly.TouchGesture.Blockly.Gesture.updateFromEvent_ (blockly_compressed.js:437)
    at Blockly.TouchGesture.Blockly.Gesture.handleMove (blockly_compressed.js:448)
    at Blockly.TouchGesture.handleMove (blockly_compressed.js:658)
    at HTMLDocument.h (blockly_compressed.js:795)
    etc...

This is because insertion markers create a duplicate of the block, and then copy all field values from the original over to the marker so that the shape is correct.

This is not a very clear error. I've personally run into it a few times, and I've also helped people on #4022, and on the forums, and again on the forums.

Expected behavior

It would be nice if this could throw a more descriptive error, for example:

Insertion marker expected field "FieldName" to exist on the marker for "BlockType". Is the domToMutation method well defined?

That may be a bit pushy, but you get the idea. I think pointing the developer in the right direction (ie domToMutation) is important (see this resource, section 6).

Stack Traces

core.js:6241 ERROR TypeError: Cannot read property 'fieldRow' of undefined
    at Blockly.InsertionMarkerManager.createMarkerBlock_ (blockly_compressed.js:304)
    at new Blockly.InsertionMarkerManager (blockly_compressed.js:299)
    at new Blockly.BlockDragger (blockly_compressed.js:318)
    at Blockly.TouchGesture.Blockly.Gesture.startDraggingBlock_ (blockly_compressed.js:443)
    at Blockly.TouchGesture.Blockly.Gesture.updateIsDraggingBlock_ (blockly_compressed.js:440)
    at Blockly.TouchGesture.Blockly.Gesture.updateIsDragging_ (blockly_compressed.js:442)
    at Blockly.TouchGesture.Blockly.Gesture.updateFromEvent_ (blockly_compressed.js:437)
    at Blockly.TouchGesture.Blockly.Gesture.handleMove (blockly_compressed.js:448)
    at Blockly.TouchGesture.handleMove (blockly_compressed.js:658)
    at HTMLDocument.h (blockly_compressed.js:795)
defaultErrorLogger @ core.js:6241
handleError @ core.js:6294
next @ core.js:42627
schedulerFn @ core.js:37132
__tryOrUnsub @ Subscriber.js:183
next @ Subscriber.js:122
_next @ Subscriber.js:72
next @ Subscriber.js:49
next @ Subject.js:39
emit @ core.js:37092
(anonymous) @ core.js:41707
invoke @ zone-evergreen.js:364
run @ zone-evergreen.js:123
runOutsideAngular @ core.js:41501
onHandleError @ core.js:41704
handleError @ zone-evergreen.js:368
runTask @ zone-evergreen.js:170
invokeTask @ zone-evergreen.js:480
invokeTask @ zone-evergreen.js:1621
globalZoneAwareCallback @ zone-evergreen.js:1647
3core.js:6241

 ERROR TypeError: Cannot read property 'dragBlock' of null
    at Blockly.TouchGesture.Blockly.Gesture.handleMove (blockly_compressed.js:448)
    at Blockly.TouchGesture.handleMove (blockly_compressed.js:658)
    at HTMLDocument.h (blockly_compressed.js:795)
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:41645)
    at ZoneDelegate.invokeTask (zone-evergreen.js:398)
    at Zone.runTask (zone-evergreen.js:167)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:480)
    at invokeTask (zone-evergreen.js:1621)
    at HTMLDocument.globalZoneAwareCallback (zone-evergreen.js:1647)
defaultErrorLogger @ core.js:6241
handleError @ core.js:6294
next @ core.js:42627
schedulerFn @ core.js:37132
__tryOrUnsub @ Subscriber.js:183
next @ Subscriber.js:122
_next @ Subscriber.js:72
next @ Subscriber.js:49
next @ Subject.js:39
emit @ core.js:37092
(anonymous) @ core.js:41707
invoke @ zone-evergreen.js:364
run @ zone-evergreen.js:123
runOutsideAngular @ core.js:41501
onHandleError @ core.js:41704
handleError @ zone-evergreen.js:368
runTask @ zone-evergreen.js:170
invokeTask @ zone-evergreen.js:480
invokeTask @ zone-evergreen.js:1621
globalZoneAwareCallback @ zone-evergreen.js:1647
core.js:6241

 ERROR TypeError: Cannot read property 'endBlockDrag' of null
    at Blockly.TouchGesture.Blockly.Gesture.handleUp (blockly_compressed.js:449)
    at Blockly.TouchGesture.handleUp (blockly_compressed.js:659)
    at HTMLDocument.h (blockly_compressed.js:795)
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:41645)
    at ZoneDelegate.invokeTask (zone-evergreen.js:398)
    at Zone.runTask (zone-evergreen.js:167)
    at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:480)
    at invokeTask (zone-evergreen.js:1621)
    at HTMLDocument.globalZoneAwareCallback (zone-evergreen.js:1658)

Additional context

There is a custom error for getMatchingConnection:

Blockly.Block.prototype.getMatchingConnection = function(otherBlock, conn) {
  var connections = this.getConnections_(true);
  var otherConnections = otherBlock.getConnections_(true);
  if (connections.length != otherConnections.length) {
    throw Error("Connection lists did not match in length.");
  }
  for (var i = 0; i < otherConnections.length; i++) {
    if (otherConnections[i] == conn) {
      return connections[i];
    }
  }
  return null;
};

Which is nice. But this might be able to be improved as well.

There may be additional areas related to insertion markers that could use more descriptive errors. But these are the two I have identified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions