NetLogo / LevelSpace

This is the LevelSpace extension repository. LevelSpace allows you to run NetLogo models |: from inside NetLogo models :|
Other
19 stars 8 forks source link

Add local stack traces to child model errors #145

Closed qiemem closed 1 year ago

qiemem commented 1 year ago

Adds netlogo code stack traces relative to child model code to child model errors:

image

I would've liked to have had line numbers in there as well, but didn't want to take the time to figure out how to convert from character number to line number, so opted for including the expression with arguments to help disambiguate in larger procedures. Obviously, jumping straight to the source point when GUI would be ideal, but this is still a significant improvement.

qiemem commented 1 year ago

Oh, how do you put newlines into expected errors in language tests? That will be needed to get tests passing. Or if there's a way to just check a substring of the message.

LaCuneta commented 1 year ago

Oh, how do you put newlines into expected errors in language tests? That will be needed to get tests passing.

Backslash should work: https://github.com/NetLogo/NetLogo/blob/hexy/test/reporters/CommandLambda.txt#L142-L153

qiemem commented 1 year ago

Ah of course!

However, still having problems. Here's the test code:

  O> ls:ask 0 [ error "hi" ] => ERROR Extension exception: Model 0 (Blank.nlogo) encountered an error at expression 'error "hi"':\
  \
  hi\
  error while observer running ERROR\
    called by (anonymous command: [ error "hi" ])\
    called by (anonymous command: [ [__lsargs] -> __apply [ error "hi" ] __lsargs ])\
    called by procedure __EVALUATOR

but its failing with:

[info] - ls::ls-errors-propogate *** FAILED ***
[info]   NormalMode: command: ls:ask 0 [ error "hi" ] Expected "...ession 'error "hi"':[\n\nhi\nerror while observer running ERROR\n  called by (anonymous command: [ error "hi" ])\n  called by (anonymous command: [ [__lsargs] -> __apply [ error "hi" ] __lsargs ])\n]  called by procedur...", but got "...ession 'error "hi"':[
[info]   
[info]   hi
[info]   error while observer running ERROR
[info]     called by (anonymous command: [ error "hi" ])
[info]     called by (anonymous command: [ [__lsargs] -> __apply [ error "hi" ] __lsargs ])
[info]   ]  called by procedur..." (AbstractTestLanguage.scala:131)
LaCuneta commented 1 year ago

Hmm, are you using the STACKTRACE keyword instead of ERROR? That's what it looks like in the language test parser. Oh I guess that is documented, too. If that keyword doesn't work for you just let me know and we can modify the language test parser to allow multi-line errors in general, too. I think using hard-coded \ns should work as well, but that's just as a workaround.

qiemem commented 1 year ago

Ah! Perfect. Thanks! Should be good to go now.

I realized an alternative strategy here would have been to bubble up an error with a concatenated stack trace rather (by overriding computeRuntimeErrorMessage, passing in a augmented activation). Might've been a bit cleaner. Probably overengineering it though.