Debugging Exported Ruby
Posted: Mon Jun 08, 2020 8:00 pm
I just had a PM from a forum member with an interesting Ruby problem. The Ruby code works fine when in FlowStone, but either doesn't get executed or fails somehow when its inside a VST export. Of course, in an export, there's normally no way to see if there's a Ruby error - there are no red borders to follow or RubyEdit error messages.
So here's a quick tip for how you might debug something like this - assuming that you know what code it is that isn't doing what you expect. You need to surround the code under test with a clause like this...
Ideally, you want as little code inside there as possible, to narrow down where the problem is. If the code under test is inside a method, make sure that the whole of the above code is inside the method definition.
Now, one of three things will happen...
- The code runs OK, in which case you get a messageBox saying so. The problem must be somewhere else.
- A messageBox pops up containing an error message (the box text) and error type (the box title).
- There is no messageBox at all - the code didn't even get executed.
This will work the same whether it is inside an export or inside FlowStone (and you'll still get red module borders etc. if the code fails) - so you can check whether the test code works inside FlowStone to make sure the messageBox works properly before exporting.
The second messageBox argument can be any String of text that you like, of course - so you can refine the debugging by creating your own strings to display - for example, including variable values that will help to narrow down the problem.
WARNING:
It is possible with this technique to get stuck in a loop of messageBoxes that you can't escape from if an error keeps happening repeatedly (say, if a ticker is triggering it).
ALWAYS SAVE A BACKUP OF YOUR SCHEMATIC FIRST!!!!
So here's a quick tip for how you might debug something like this - assuming that you know what code it is that isn't doing what you expect. You need to surround the code under test with a clause like this...
Code: Select all
begin
#### CODE UNDER TEST HERE ####
messageBox(0, "Code was executed")
rescue Exception => error
messageBox(0, error.message, error.class)
raise(error)
end
Ideally, you want as little code inside there as possible, to narrow down where the problem is. If the code under test is inside a method, make sure that the whole of the above code is inside the method definition.
Now, one of three things will happen...
- The code runs OK, in which case you get a messageBox saying so. The problem must be somewhere else.
- A messageBox pops up containing an error message (the box text) and error type (the box title).
- There is no messageBox at all - the code didn't even get executed.
This will work the same whether it is inside an export or inside FlowStone (and you'll still get red module borders etc. if the code fails) - so you can check whether the test code works inside FlowStone to make sure the messageBox works properly before exporting.
The second messageBox argument can be any String of text that you like, of course - so you can refine the debugging by creating your own strings to display - for example, including variable values that will help to narrow down the problem.
WARNING:
It is possible with this technique to get stuck in a loop of messageBoxes that you can't escape from if an error keeps happening repeatedly (say, if a ticker is triggering it).
ALWAYS SAVE A BACKUP OF YOUR SCHEMATIC FIRST!!!!