Charles,

I wasn't sure we had an example extension that included a primitive that
accepts a task as input, but I found one: Nicolas Payette's `rnd`
extension.  Looking at his code and test cases was helpful.

So what's happening is you're getting an ArrayIndexOutOfBoundsException,
and the "2" is the message in that exception.  (We can blame the
terse/unhelpful error message on Sun/Oracle; sure would be nice if it
said what array and how big...)

One way to proceed would be to catch that exception and then throw an
ExtensionException.  But I wouldn't actually suggest that approach
because an ArrayIndexOutOfBoundsException might have a different cause,
so you couldn't be confident you'd be issuing a correct error message.

So I would suggest handling it the way I see that Nicolas did, which is
to do your own arity checking before calling `report` on the
ReporterTask.

Here's the relevant parts of Nicolas's code:

https://github.com/NetLogo/Rnd-Extension/blob/bab4899e2f5ccc7281c4476056e4ff9463c59258/src/main/scala/org/nlogo/extensions/rnd/Primitives.scala#L40-L42
https://github.com/NetLogo/Rnd-Extension/blob/bab4899e2f5ccc7281c4476056e4ff9463c59258/tests.txt#L183-L188

Note that the arity checking unfortunately requires downcasting from
`api.Task` to `nvm.Task`.  I just opened
https://github.com/NetLogo/NetLogo/issues/554 on that (and on the
lack of documentation on the need to arity check at all).

Note also this similar code in the implementation of the `_runresult`
primitive:

https://github.com/NetLogo/NetLogo/blob/f6d990160aef29e1928fc7faa986ae7552541504/src/main/org/nlogo/prim/etc/_runresult.scala#L44-L46

but Nicolas didn't call `missingInputs` in his code because of
https://github.com/NetLogo/NetLogo/issues/419 .

I hope this clears everything up?

--
Seth Tisue | Northwestern University | http://tisue.net
developer, NetLogo: http://ccl.northwestern.edu/netlogo/

-- 
You received this message because you are subscribed to the Google Groups 
"netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netlogo-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to