Fork me on GitHub
#clj-kondo
<
2021-04-05
>
cjsauer16:04:07

When writing a custom hook, can I pass line/col metadata in the ex-data of an error?

cjsauer16:04:42

I want to treat this problem as an error, not a warning, but still retain helpful line/col info

cjsauer16:04:05

Right now when I throw, it “puts” the error onto the top-level form, but I have the exact line/col info of the real issue

cjsauer16:04:32

(throw (ex-info "defmutation handlers must take 1 argument"
                          {:type :fulcro/defmutation
                           :row row
                           :col col}))

cjsauer16:04:35

Something like this

borkdude16:04:47

yes, that should work

borkdude16:04:21

well, type isn't picked up from ex-data, but row and col are

borkdude16:04:03

it probably should, but it isn't the case right now. but you can use reg-finding! to do what you want

cjsauer16:04:29

Can reg-finding! be configured to be a fatal error?

borkdude16:04:44

you have to set :level :error

cjsauer16:04:51

Ahh duh, I see it now

borkdude16:04:29

note that the user will also have to configure :fulcro/defmutation in the linter config and set a level for it

borkdude16:04:46

I think the :level isn't even relevant from where it's emitted, it's always the one from the config

cjsauer16:04:13

Hm yea, must be, still can’t quite get it working

cjsauer16:04:33

I think I’m doing something slightly weird is the problem. Basically, I’m transforming fulcro’s defmutation into something like this:

(defn my-mutation
  [params]
  (letfn [(action [env])
          (remote [env])]
    (action nil)
    (remote nil)))
It’s “close enough” to what I want the linting to do, but it’s giving me stray errors like “action is called with 1 arg instead of 0"…I’m trying to override those subsequent/general linters with my own very specific error messages, if that makes sense

borkdude16:04:10

I don't know these macros to say with confidence if that makes sense.

borkdude16:04:03

but in general I think it does

cjsauer19:04:48

Inside of a reg-finding! map, how should I qualify :type keywords? I’m thinking something like this: :clj-kondo.fulcro.defmutation/handler-arity

cjsauer19:04:30

Originally I had :com.fulcrologic.fulcro.mutations.defmutation/handler-arity, but that’s not a domain I own, so I shouldn’t be adding keys to it yea? Still figuring out how to namespace keywords generally…

borkdude19:04:34

yeah, I think your proposal is reasonable

👍 3