duct

2018-11-19T10:56:59.092400Z

I have an issue where if I turn (clojure.spec.test.alpha/instrument) on to instrument my specs; I get an exception when running (reset). Any idea what that might be?

2018-11-19T10:57:12.092500Z

2018-11-19T11:00:29.093200Z

Running module.ataraxy 0.3.0-alpha3

2018-11-19T11:06:18.094300Z

unstrumenting and reseting again causes things to work again

scottlowe 2018-11-19T19:37:18.095700Z

@rickmoynihan If you are instrumenting an Ataraxy coercer, then try executing (clojure.tools.namespace.repl/refresh-all) after (clojure.spec.test.alpha/instrument) and before your (reset). Ataraxy compiles routes and coercers here: https://github.com/weavejester/ataraxy/blob/master/src/ataraxy/core.clj#L255-L261 When instrument is turned on, a dynamic spec-checking-fn wrapper function (a.k.a “checked”) is swapped in for the raw coercer function by instrument here: https://github.com/clojure/spec.alpha/blob/master/src/main/clojure/clojure/spec/test/alpha.clj#L171-L177 More specifically, the clojure.spec.test.alpha$spec_checking_fn$fn__3026 mentioned on line 187 in your stacktrace. reset only reloads namespaces that it knows has changed, but it doesn’t know about this “new” coercer function, so it’s best to reload all namespaces with refresh-all, so that Ataraxy can compile the new definition. Certainly, (regardless of the exact mechanism in play) I managed to reproduce your error with instrument and reset and a custom instrumented coercer; and the issue went away after executing refresh-all.

2018-11-19T22:43:36.099200Z

Yes, I think you’re right @scottlowe, that the problem is with compile. However I don’t think your solution actually works; as whilst it stops the exception, the refresh-all clobbers the instrumented definition of the coercer… so the end result of the fix is the same as not instrumenting at all.

2018-11-19T22:48:10.101600Z

I wonder if manually halting initing might work better after instrumenting, to avoid the refresh altogether…

2018-11-19T22:51:35.101900Z

Nope, that causes the same problem

2018-11-19T22:52:11.102600Z

I wonder if the eval in ataraxy compile is the problem; eval is a bit fishy

scottlowe 2018-11-19T22:54:59.104900Z

@rickmoynihan I did have instrument working after a refresh-all and a reset. However, I may have reported the sequence of commands incorrectly. Perhaps you need to execute instrument twice (?). Haven’t got it in front of me now, but I did have some luck with this (no compile error after a reset) and then I deliberately sent data that would fail the instrumented coercer spec, and it did.

2018-11-19T22:55:52.105900Z

hmmm ok, cos that’s what I’ve tried and its not working… but the steps are a little fiddly

scottlowe 2018-11-19T22:55:59.106100Z

Perhaps I just got lucky with compilation, and it’s not deterministic :thinking_face:

2018-11-19T22:56:25.106500Z

lol - lets hope it’s deterministic

2018-11-19T22:57:14.107100Z

regardless I still don’t quite understand why it errors like this

scottlowe 2018-11-19T22:57:51.107900Z

The constructor error itself?

2018-11-19T22:58:13.108700Z

If you find anything that needs fixing in Ataraxy, report it as an issue on the Github repo.

2018-11-19T22:58:20.109Z

yeah - I understand it’s probably stale

2018-11-19T22:59:11.110300Z

Cheers @weavejester… I’ll certainly file an issue

2018-11-19T22:59:32.110900Z

just trying to understand the cause

2018-11-19T23:02:10.113Z

It might be that the coercers are loaded by symbol, without a corresponding :require in the ns declaration.

2018-11-19T23:02:28.113500Z

tools.namespace relies on statically reading the ns declaration to work out the dependencies.

2018-11-19T23:03:15.114500Z

interesting… the coercers are just defined in the system config map… so yeah no :require

2018-11-19T23:04:11.115900Z

Though I'm not sure why the system reset wouldn't solve that, since the routes should be recompiled every time.

2018-11-19T23:04:35.116500Z

@weavejester: would it be possible to avoid that eval?

2018-11-19T23:05:48.118100Z

I'm not sure how it would be. Ataraxy compiles its routes into code before running. Since that happens after compilation time if it's loaded from an Integrant config, it needs an eval.

2018-11-19T23:05:57.118500Z

I'd look into it more, but I need to get to bed 🙂

👍 1
scottlowe 2018-11-19T23:06:14.119100Z

@rickmoynihan I looked at this error under the debugger and Reflector/invokeConstructor was looking for a 4 arg constructor for the instrumented function class that Ataraxy had in its coercers map, rather than the original coercer function class which had a different ctor arity, so something is out of step in terms of compilation.

2018-11-19T23:23:21.120800Z

Ok I think the work around is simple, just (st/instrument) after the (reset); that works as expected

😌 1