ajm_objects
ajm_objects copied to clipboard
ajm.ruby not writing Ruby exceptions to Max window
Hi Adam,
ajm.ruby is very cool! However, how do you actually go about debugging your Ruby code? All that gets written to the Max window is "could not evaluate" (runtime) or "Error evaluating script file" (loadtime).
Would it be possible to get the Ruby exception & stacktrace? Or is this getting eaten up by the BSF evaluator? (I see some code in eval() in ajm/ruby.java to spit out a stacktrace, but I never see it—and suppose it's the Java stacktrace anyway.)
Any tips very welcome, thanks! Adam
Hi sorry for not responding before.
This is definitely a pain point with ajm.ruby and I'll be looking for ways to make it better.
For now, I think the best thing to do is stick a begin/rescue block around your entire script. In the rescue block, try printing out the stack trace with 'puts $!' or something along those lines.
You can also try $DEBUG=true at the top of your script but I don't know if that will help.
Finally, as a general suggestion: I personally try to develop and test most of my code outside of Max, and then write a lightweight "bridge" script that the is used by ajm.ruby to load everything into Max and expose any methods I want to use in the patch. For best results, you should develop against whatever version of JRuby the ajm.ruby help patch says its using.
The current version of JRuby w/ BSF in ajm.ruby is pretty bad about swallowing exceptions and not giving useful stack traces. I believe the newer versions handle this better. I will be releasing an update to ajm objects soon-ish (this summer) so keep an eye out for that.
Got it, thanks!
begin/rescue blocks work great inside each method; no dice just wrapping the whole script in one. $DEBUG didn't seem to do anything, either.
Anyway, wish I had thought of this sooner; I'm able to do meaningful Ruby dev now. Now to get it all cooking inside Max for Live!
Cool. Thanks for letting me know wrapping the whole script wasn't helpful. One day I'll try to put together a FAQ with these sorts of tips in it.
FYI - there's some nice syntax sugar in ruby: you can add a rescue block to a function without a begin block:
def foo
stuff_that_might_blowup()
rescue
puts $!
end