jrubyfx icon indicating copy to clipboard operation
jrubyfx copied to clipboard

Symbol conversion procs should report better message

Open enebo opened this issue 12 years ago • 1 comments

When you call a color converter (just an example) which takes a symbol we get a rather weird error message to anyone who is not a JRubyFX hacker:

Exception running Application:
#<TypeError: cannot convert instance of class org.jruby.RubySymbol to class javafx.scene.paint.Paint>
/Users/enebo/work/jrubyfx/lib/jrubyfx/core_ext/precompiled.rb:908:in `fill='

Now we know something went wrong with fill= but this is pretty confusing to new users and we can give better feed back. Here is what I have a patch for (I will commit it as a discussion provoker):

Exception running Application:
#<ArgumentError: No such color: redbull>
/Users/enebo/work/jrubyfx/lib/jrubyfx/utils/common_converters.rb:144:in `CommonConverters'
org/jruby/RubyProc.java:264:in `call'
/Users/enebo/work/jrubyfx/lib/jrubyfx/core_ext/precompiled.rb:908:in `fill='

So the backtrace now shows common converters and the proc call for the converter but the message is likely to be really obvious. It would be possible to make a much more sophisticated coercion mechanism but I feel this is a big improvement for a tiny amount of work.

enebo avatar Oct 21 '13 23:10 enebo

c6e37b2 is a commit which enables this behavior for color converter. We can revert this if we decide we dislike it but I hate seeing the RubySymbol stuff. I think we should add this to all symbol-based converters since a symbol is always an invalid type to pass to a FX method.

I played a little with a more robust mechanism to converters to report at he proper place but without a lot of codegen I don't see a nice way of doing it.

enebo avatar Oct 21 '13 23:10 enebo