From 738d06a4640474aec50bca7789d534c6e9768b31 Mon Sep 17 00:00:00 2001 From: Erik Pasternak Date: Tue, 18 Dec 2018 11:52:43 -0800 Subject: [PATCH] Avoid crashing when a procedure input has an empty string Fixes #1958 This will drop the input when it's in the empty string state. This causes the block to remove the input and re-add it when the text is reverted, but prevents the breakage. A followup fix should leave the input alone instead of removing it, but this works for now. --- blocks/procedures.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/blocks/procedures.js b/blocks/procedures.js index 0511ed232..7f6e0965f 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -159,7 +159,11 @@ Blockly.Blocks['procedures_defnoreturn'] = { this.arguments_.push(varName); var variable = Blockly.Variables.getOrCreateVariablePackage( this.workspace, varId, varName, ''); - this.argumentVarModels_.push(variable); + if (variable != null) { + this.argumentVarModels_.push(variable); + } else { + console.log('Failed to create a variable with name ' + varName + ', ignoring.'); + } } } this.updateParams_(); @@ -216,7 +220,12 @@ Blockly.Blocks['procedures_defnoreturn'] = { var varName = paramBlock.getFieldValue('NAME'); this.arguments_.push(varName); var variable = this.workspace.getVariable(varName, ''); - this.argumentVarModels_.push(variable); + if (variable != null) { + this.argumentVarModels_.push(variable); + } else { + console.log('Failed to get variable named ' + varName + ', ignoring.'); + } + this.paramIds_.push(paramBlock.id); paramBlock = paramBlock.nextConnection && paramBlock.nextConnection.targetBlock();