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

getVariable can fail #2107

Closed
EricTheMagician opened this issue Nov 5, 2018 · 3 comments
Closed

getVariable can fail #2107

EricTheMagician opened this issue Nov 5, 2018 · 3 comments

Comments

@EricTheMagician
Copy link

EricTheMagician commented Nov 5, 2018

Problem statement

Bug Report:
In the getVariable function of variable.js (

Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) {
),

If an id is specified, but a variable is not found, it does not fallback to the opt_name + opt_type.

Expected Behavior

Return the variable by opt_name + opt_type if they are specified

Actual Behavior

Returns undefined.

Steps to Reproduce

I don't know what's the simplest way for someone else to reproduce it, but this what we do in our setup.

  1. In our toolbox, we have a block that has a FieldVariable dropdown default with name "aChannel" and type orsChannel.
  2. We drag the block from the toolbox and drop it in to the main workspace.
  3. We save the xml representation of the workspace.
  4. We reload blockly and clear the browser cache (for development purposes), though I think clearing the blockly workspace is sufficient.
  5. We try to load the workspace from the xml representation in step 3.
    This generates the stack trace below.

Essentially, the getOrCreateVariablePackage calls getVariable by id, name and type.
Here, because of the toolbox, we have a variable called "aChannel", but it has a different id then the one we saved. Thus, when getVariable is called, by id, it doesn't find the one created by the toolbox. So it tries to create a new variable, but it then fails because, it technically already exists.

Stack Traces

Uncaught (in promise) Error: Variable "aChannel" is already in use and its id is "^%=4elLAJI}I@xY|apaL" which conflicts with the passed in id, "K$7zZt~4c?ZYE-d6~*9-".
    at Blockly.VariableMap.createVariable (variable_map.js:177)
    at Blockly.WorkspaceSvg.Blockly.Workspace.createVariable (workspace.js:321)
    at Blockly.WorkspaceSvg.createVariable (workspace_svg.js:1094)
    at Object.Blockly.Variables.createVariable_ (variables.js:557)
    at Object.Blockly.Variables.getOrCreateVariablePackage (variables.js:490)
    at Object.Blockly.Xml.domToFieldVariable_ (xml.js:809)
    at Object.Blockly.Xml.domToField_ (xml.js:841)
    at Object.Blockly.Xml.domToBlockHeadless_ (xml.js:699)
    at Object.Blockly.Xml.domToBlockHeadless_ (xml.js:713)
    at Object.Blockly.Xml.domToBlockHeadless_ (xml.js:713)

Operating System and Browser

  • Desktop Chrome

Additional Information

I can provide a PR, but it's not clear how to format it with respect to the style guide.

@rachel-fenichel
Copy link
Collaborator

Interesting. So you want the else if (opt_name) to become an if. The if (id) part would run, and return if it found anything, and then fall through to the other path on failure. Is that accurate?

P.S. Sorry for the delay in responding, and thanks for the clear write-up.

@EricTheMagician
Copy link
Author

@rachel-fenichel
Yes, exactly.

@EricTheMagician
Copy link
Author

@rachel-fenichel
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants