component

2017-10-06T20:46:01.000174Z

Didn't know that there was a component channel 🙂. I've been loving the idea of component, and structured all my projects with it. However, the namespace refresh seems quite unstable in my projects. Quite frequently it just breaks because it's unable to find some (random?) namespace. Does anyone here have similar problems? How did you solve them?

2017-10-06T20:54:50.000017Z

stex: refresh can often reveal structural problems that already exist

2017-10-06T20:55:41.000424Z

e.g. cyclical dependencies of one k ind or another, missing dependencies, using import and java constructors for records instead of require and the factory functions

2017-10-06T21:01:22.000073Z

@hiredman Interesting! Any idea how to debug such problems?

2017-10-06T21:02:40.000180Z

I would start by looking at the namespace named in the error message, and then trying to load that namespace with require in otherwise clean repl

2017-10-06T21:03:53.000369Z

@hiredman Starting a new repl 🙂. Hmm..

2017-10-06T21:05:01.000394Z

it is very possible you'll find that the code on disk isn't valid and won't compile in a fresh repl, and there was some left over state that was allowing it to compile for whatever reason

2017-10-06T21:05:53.000120Z

you can also, without a fresh repl, try (require 'whatever.ns :reload)

2017-10-06T21:06:44.000235Z

the refresh error messages tend to just point at the namespace that is a problem, without telling you want the problem is, where as if you manually load the code you will get a real error message that tells you what the error is

2017-10-06T21:08:07.000097Z

I'm quite sure the code in the namespaces is working correctly. I think it's probably more like a cyclical dependency or something.

2017-10-06T21:08:40.000076Z

does the code load in a fresh repl?

2017-10-06T21:08:51.000445Z

I've started a new REPL repl and required the namespace, which worked, than loaded everything and than required with the :reload flag and works too.

2017-10-06T21:09:21.000261Z

when I refresh it doesn't... But with manually requiring with reload works

2017-10-06T21:11:05.000060Z

if its a circular dependency in general, if you rare requiring via the ns form, you will get an error for circular deps, if you are doing something more complicated then you have taken your fate in to your own hands

2017-10-06T21:12:28.000352Z

What is "more complicated"? I only require via the ns form but never seen a warning

2017-10-06T21:13:34.000430Z

if you are only using ns, then I wouldn't worry about it

2017-10-06T21:14:08.000270Z

are you defining records, types, or using multi methods or protocols?

2017-10-06T21:15:34.000047Z

Only records, as components. But I don't use them directly, only the helper function which calls map->Web for example.

2017-10-06T21:21:00.000014Z

Hmmm. So, I've been trying to remove the require in the ns form of the function which cannot be found. It fixes that specific error-case, but than another namespace doesn't load. Have done this 8 times now and doesn't seem to stop

2017-10-06T21:22:45.000003Z

you may be walking back through a cycle, the require code tries to detect those and throw an error, but I dunno, there may be something that circumvents that

2017-10-06T21:23:40.000218Z

what build tool are you using? is refresh able to correctly find you source code?

2017-10-06T21:26:19.000105Z

I'm just using a simple leiningen setup, no special build steps. Well, refresh isn't able to find namespaces, so I don't think it can find all the source code...?

2017-10-06T21:26:22.000087Z

Not sure 😛

2017-10-06T21:27:23.000322Z

@stex any chance your namespace is using a namespace that it doesn’t require, but is available because another namespace required it?

2017-10-06T21:27:36.000058Z

this could easily go bad when refreshing (and is a bad idea anyway)

2017-10-06T21:28:29.000405Z

@noisesmith Sounds plausable. I'll start grepping the source files

2017-10-06T21:28:32.000239Z

also, what is the specific error message you are seeing for the missing namespace?

2017-10-06T21:31:05.000066Z

`

2017-10-06T21:32:37.000219Z

@noisesmith I cannot find any usages of a namespace without requiring it first. Only clojure.string and http://clojure.java.io, but that is fine, right?

2017-10-06T21:32:52.000217Z

no, but that isn’t your problem

2017-10-06T21:33:13.000081Z

clojure.string isn’t loaded by default - so it can work to use it without a require in dev, but break when running from a jar

2017-10-06T21:33:47.000063Z

http://clojure.java.io is used by clojure itself in bootstrapping, so that won’t break the same way (currently) but there’s no promise that implicitly relying on it being present won’t break in the future

2017-10-06T21:34:06.000145Z

considering that the fix is just one line in a require form, it’s better to add it for consistency’s sake anyway

2017-10-06T21:35:42.000287Z

so you are using slamhound to invoke c.t.n/reload ? if not, it could be that something slamhound is trying to do gets broken by the refresh

2017-10-06T21:35:42.000341Z

@noisesmith Yep, I've replaced both occurrences right away 👍. Doesn't solve reset though.

2017-10-06T21:36:00.000172Z

what’s the slamhound process doing exactly?

2017-10-06T21:36:50.000253Z

iirc slamhound messes with your namespaces, and I could see it going bonkers if someone deletes a namespace (and that’s something refresh does in order to get a clean state)

2017-10-06T21:37:46.000040Z

Hmm.. Seems like slamhound is something of cljr-refactor in cider... Let's try a simple lein repl session...

2017-10-06T21:38:33.000326Z

OK - if you aren’t explicitly using slamhound to drive your refresh, I bet refresh and slamhound are getting in a spat 😄

2017-10-06T21:39:01.000182Z

I don't know what slamhound is actually, I'm just using cljr-refactor in cider 😛

2017-10-06T21:39:15.000215Z

Well, lein repl gives the same issue, no stacktrace though

2017-10-06T21:39:16.000002Z

yeah, clj-refactor is built on slamhound iirc

2017-10-06T21:39:26.000202Z

(pst) will show you the stack trace

2017-10-06T21:39:41.000128Z

wouldn’t lein repl still pull in cider if you have it set up in your profiles.clj?

2017-10-06T21:39:56.000188Z

or is the new cider injecting the plugin manually?

2017-10-06T21:40:15.000125Z

Cider is injecting the manually

2017-10-06T21:40:21.000283Z

:error-while-loading project.erp.agp.client

CompilerException java.lang.Exception: namespace 'project.erp.agp.parsers' not found, compiling:(project/erp/agp/client.clj:1:1)
user=> (pst)
CompilerException java.lang.Exception: namespace 'project.erp.agp.parsers' not found, compiling:(project/erp/agp/client.clj:1:1)
	clojure.core/throw-if (core.clj:5656)
	clojure.core/load-lib (core.clj:5742)
	clojure.core/load-lib (core.clj:5717)
	clojure.core/apply (core.clj:648)
	clojure.core/load-libs (core.clj:5774)
	clojure.core/load-libs (core.clj:5758)
	clojure.core/apply (core.clj:648)
	clojure.core/require (core.clj:5796)
	clojure.core/require (core.clj:5796)
	project.erp.agp.client/eval28368/loading--5569--auto----28369 (client.clj:1)
	project.erp.agp.client/eval28368 (client.clj:1)
	project.erp.agp.client/eval28368 (client.clj:1)
Caused by:
Exception namespace 'project.erp.agp.parsers' not found
nil

2017-10-06T21:41:51.000378Z

When I require them manually (directly after the other output) it just works...

2017-10-06T21:41:56.000006Z

user=> (require 'project.erp.agp.parsers)
nil
user=> (require 'project.erp.agp.parsers :reload)
nil

2017-10-06T21:41:56.000035Z

@stex do you have a user.clj in that project by any chance (eg. it might have been created by a template)

2017-10-06T21:42:09.000165Z

Yep, i do use user.clj

2017-10-06T21:42:33.000274Z

There I load the (reset) functions and some other functions

2017-10-06T21:44:42.000077Z

@stex I just found this > Adding a :main to your project.clj will enable AOT compilation and thus break clojure.tools.namespace/refresh. I worked around this by declaring my main in the :uberjar profile.

2017-10-06T21:45:25.000304Z

Yep, I've seen that. I've only added the main to the :uberjar profile.

2017-10-06T21:45:37.000033Z

:thumbsup:

2017-10-06T21:45:53.000018Z

so you have no main or aot in other profiles?

2017-10-06T21:47:11.000026Z

Nop, just in the uberjar (just checked it)

2017-10-06T21:48:35.000039Z

Is it fine to load setup the reset function in the user.clj?

2017-10-06T21:49:44.000139Z

sometimes there are shenanigans going on with user.clj, in particular if it helpfully preloads some of your namespaces, so it’s worth double checking it’s not trying to be too clever

2017-10-06T21:53:00.000190Z

@stex the other gotcha with aot / refresh is that even if you only have aot / main set for uberjar, if you run a repl after uberjar without running clean first, you’ll get that same error

2017-10-06T21:53:04.000088Z

😮. For some reason the error disapears when I move the code from the user namespace to a new dev namespace

2017-10-06T21:53:51.000323Z

haha, sweet

2017-10-06T21:54:16.000048Z

Oke, just to be sure it isn't the lein clean + uberjar thing I'll revert 🙂

2017-10-06T21:54:28.000206Z

Sweet, but weird 😄

2017-10-06T21:54:33.000254Z

Curious why this works

2017-10-06T21:55:01.000003Z

do weird things, get weird results, some templates (eg. luminus) put sketchy stuff in user.clj

2017-10-06T21:55:26.000082Z

I don't like templates 🙂. Created user myself and it's super minimal

2017-10-06T21:55:51.000046Z

oh, OK - well regardless of why I helped, glad I could help haha

2017-10-06T21:56:18.000112Z

(ns user
  (:import java.lang.Runtime)
  (:require [figwheel-sidecar.system :as sys]
            [com.stuartsierra.component.repl :refer [set-init system start stop reset]]
            [com.stuartsierra.component :as component]
            [project.utils.env :refer [env]]
            [project.components.system :refer [create-system-map]]))

(defrecord ScssCompiler []
  component/Lifecycle
  (start [this]
    (if-not (:process this)
      (do
        (println "Starting SCSS watch process...")
        (assoc this :process
               (.exec (Runtime/getRuntime) "bin/watch-sass")))
      this))
  (stop [this]
    (when-let [process (:process this)]
      (println "Stopping SCSS watch process...")
      (.destroy process))
    this))

(defn cljs []
  (sys/cljs-repl (:figwheel-system system)))

(defn dev-system [_]
  (assoc (create-system-map env)
         :scss-compiler (->ScssCompiler)
         :figwheel-system (sys/figwheel-system
                           (assoc-in (sys/fetch-config) [:data :build-ids] ["dev" "figwheel-test"]))
         :css-watcher (component/using
                       (sys/css-watcher {:watch-paths ["resources/public/css"]})
                       {:figwheel-server :figwheel-system})))

(set-init dev-system)

2017-10-06T21:56:27.000367Z

That's my user.clj, Do you find anything weird?

2017-10-06T21:57:18.000379Z

Oh, oke! It works now also when I lein clean and keep everything in the user.clj

2017-10-06T21:57:40.000298Z

aha, so it was a caching issue

2017-10-06T21:57:50.000299Z

that makes a lot more sense, that user.clj looks fine

2017-10-06T21:58:30.000261Z

@stex instead of remembering to run lein clean, you could make sure the target-path of uberjar isn’t in the repl’s classpath

2017-10-06T21:59:03.000063Z

How do you do that specifically?

2017-10-06T21:59:08.000201Z

by eg. setting a custom compile-path or target-path (forget the config name) under the uberjar profile

2017-10-06T21:59:18.000085Z

lein help sample should reference it somewhere

2017-10-06T21:59:34.000266Z

Ok!

2017-10-06T21:59:40.000207Z

Thanks man!!

2017-10-06T22:00:18.000013Z

Super happy I know it's a caching problem. I've been having these weird issues in all my projects for months now and was really really fed up with it

2017-10-06T22:01:40.000291Z

@stex I’ve hit enough random leiningen caching problems (and wasted enough time on them) that I now double check if lein clean fixes my issue before even thinking about the actual bug if I have any problem with finding namespaces or classes

2017-10-06T22:02:11.000157Z

Haha, will remember that for the next time 😉

2017-10-06T22:02:18.000089Z

but it’s so automatic that I sometimes forget to recommend it for others

2017-10-06T22:02:19.000005Z

Could have saved me a lot of time

2017-10-06T22:02:22.000076Z

😄

2017-10-06T22:02:56.000343Z

Yep, i've tried a uberjar, ran reset and the issue reappeared. Fixed by lein clean

2017-10-06T22:02:58.000218Z

nice 🙂

2017-10-06T22:07:25.000163Z

It's late here already, going to bed. Thanks @noisesmith and @hiredman!! Much appreciated.