Blocker - Facing error - Uncaught Error: Language "Python" does not know how to generate code for block type

237 views
Skip to first unread message

Naresh Chaudhari

unread,
Dec 18, 2021, 8:37:01 AM12/18/21
to blo...@googlegroups.com
Hi All, Getting below error while dragging any block from the testcase category. Other category blocks is working as expected. (Did this POC work before 5 months, and yesterday I opened the application started facing this issue so, started debugging but not got a solution, So please anyone help me out here)
generator.js:197 Uncaught Error: Language "Python" does not know how to generate  code for block type "<custom_raise_exception(block_name)>".
    at Blockly.Generator.blockToCode (generator.js:197)
    at Blockly.Generator.workspaceToCode (generator.js:104)
    at showCode ((index):1701)
    at Blockly.WorkspaceSvg.Blockly.Workspace.fireChangeListener (workspace.js:665)
    at Blockly.Events.fireNow_ (events.js:247)

image.png

Please help me out... 

photo
NARESH CHAUDHARI
Telaverge Communications India Pvt Ltd. 

Mobile: +91 9408870158 |  Skype: +91 9408870158

Gmail: chaudhary...@gmail.com

Address: Silver Software Campus,
                      KIADB Export Promotion Industrial Area,
                      Whitefield, Bengaluru, Karnataka 560066
  
  

Naresh Chaudhari

unread,
Dec 18, 2021, 8:41:14 AM12/18/21
to Blockly
Here is implementation code
```
Blockly.Python['custom_raise_exception'] = function (block) {
    var text_exception_message = block.getFieldValue('EXCEPTION_MESSAGE');
   
    var code = 'raise Exception("' + text_exception_message + '")\n';
    return code;
};

Blockly.Blocks['custom_raise_exception'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("raise exception")
        .appendField(new Blockly.FieldTextInput("default"), "EXCEPTION_MESSAGE");
    this.setInputsInline(false);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour("%{BKY_TESTCASE_HUE}");
 this.setTooltip("");
 this.setHelpUrl("");
  }
};
    '<block type="custom_raise_exception"></block>' +
```

Neil Fraser

unread,
Dec 22, 2021, 4:57:33 PM12/22/21
to blo...@googlegroups.com
This code looks exactly correct.  My guess is that somehow the code isn't getting loaded.

On the console, type:
  Blockly.Blocks.custom_raise_exception
You should see a function be printed.  Next type:
  Blockly.Python.custom_raise_exception
Again, a function should be printed, but I assume that it will report 'undefined' instead.  If that is the case, then you need to figure out why your code isn't loading.  Let us know what you find and we'll help as we can.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/3b1e5515-acca-4842-9004-8aaa16c8b4ddn%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages