Pulling Focus with Errors: "This is what's important"

I've often made use of "definitional panic".

The idea is if you have some function which is processing data, there could be some kind of deep error in there where really you just want to call attention to whatever triggered the step.

process-some-thing: func [thing] [
    panic: func [reason] [
        <dump diagnostics pertaining to thing>
        lib/panic reason
    ]
    blah blah [
      if blah blah [panic "say something about why this was wrong"]
      ...          
      if blah blah [panic "say something about why this was wrong"]
      ...
      if blah blah [panic "say something about why this was wrong"]
   ]
]

Definitional panics are neat, and there's more to say about them. I started wondering if there could be even lighter versions of this:

process-some-thing: func [thing] [
    focus $thing

    blah blah [
      if blah blah [panic "say something about why this was wrong"]
      ...          
      if blah blah [panic "say something about why this was wrong"]
      ...
      if blah blah [panic "say something about why this was wrong"]
   ]
]

It could be a macro that generated a definitional panic for you, that would tell you "Problem happened while focusing on THING" and dump out some or all of its molded value... but then escalate the panic as normal.

So that's of course possible these days... (yay INLINER!)

But then the bigger question might be "could it trap any error while it's in scope". It could if you bracketed the ensuing code with a BLOCK!.

FWIW an INLINER could be variadic... spool everything after it into a block, and then EVAL that block. So this could be done even today.

:thinking:

Seems like it would be nice to have a cheaper way to accomplish that, than actually sucking up the rest of the feed as arguments and starting a new evaluation.

1 Like