rewrite-clj icon indicating copy to clipboard operation
rewrite-clj copied to clipboard

Identity ex-info exceptions as being thrown from rewrite-clj

Open lread opened this issue 3 years ago • 4 comments

Problem/Opportunity Rewrite-clj throws ex-info exceptions. It would be nice if a caller could easily tell if they came from rewrite-clj.

Proposed Solution @borkdude suggested adding :type :rewrite-clj to ex-data.

Alternative Solutions None at this time.

Action I can follow up with a PR sometime soon.

lread avatar Sep 12 '22 13:09 lread

A namespaced keyword would allow usage with derive. This is what I've done in SCI: :sci/error for general errors.

borkdude avatar Sep 12 '22 13:09 borkdude

A namespaced keyword would allow usage with derive. This is what I've done in SCI: :sci/error for general errors.

Cool, thanks, I'll take a peek at sci for inspiration.

lread avatar Sep 12 '22 14:09 lread

While I'm looking at exceptions I've started to look at this one.

Following sci's example we'll have a base exception :type of :rewrite-clj/error.

It will have descendants:

  • rewrite-clj.error/parse will have descendants:
    • rewrite-clj.error/unmatched-delimiter
    • rewrite-clj.error/eof (could optionally distinguish different reasons for eof with descendants, but probably won't yet)
    • rewrite-clj.error/invalid will have descendants
      • rewrite-clj.error/invalid-keyword
      • rewrite-clj.error/invalid-symbol
      • rewrite-clj.error/invalid-namespaced-map
      • ...

I'll review and update as I work my way through what rewrite-clj currently throws. (and what our usage of tools.reader currently throws, for that matter).

As always, feedback and ideas are welcome.

lread avatar Jul 06 '24 22:07 lread

An alternative to being very granular for invalid errors is to include what rewrite-clj was trying to parse as a separate map entry in the ex-info data. Our node tag is not terribly granular so this might send me to finally look at #114.

lread avatar Jul 07 '24 01:07 lread