clj-commons / rewrite-clj

Rewrite Clojure code and edn
https://cljdoc.org/d/rewrite-clj
MIT License
586 stars 54 forks source link

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

Open lread opened 1 year ago

lread commented 1 year ago

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.

borkdude commented 1 year ago

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

lread commented 1 year ago

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 commented 1 week ago

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:

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 commented 1 week ago

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.