Fork me on GitHub
#shadow-cljs
<
2019-07-07
>
mhuebert00:07:17

is there a way to report errors during lazy module loading?

mhuebert00:07:09

errors seem to be completely silent

mhuebert00:07:35

(well, until eventually ModuleManager reports error code 1)

thheller08:07:27

hmm good question. never had that problem.

thheller08:07:41

I think the whole module loading stuff uses the default closure logging stuff

thheller08:07:51

so it should log everything if you set that up correctly

mhuebert16:07:03

ModuleManager has a registerCallback fn that lets you add a callback for errors, but this is only called after it has attempted to load a script a few times, and doesn’t pass you the actual error

mhuebert18:07:59

well, found a way to listen for errors during module loading: https://gist-press.com/mhuebert/dfdf5dd94bbb944e995dc475c4421f4c I think it’s kind of crazy that ModuleManager’s default is to silently swallow errors. (I saw a comment in the source where they wonder if they should throw, so they have been thinking about this)

4
thheller18:07:27

did you not test setting up the closure logging stuff?

thheller18:07:05

there is definitely logging related code

thheller18:07:10

goog.log.warning(
        this.logger, 'Loaded incomplete code for module(s): ' + moduleIds, e);
etc

mhuebert18:07:37

It wasn’t obvious to me how to actually use it. I enabled debug mode in one of the namespaces but it didn’t have an effect

mhuebert18:07:17

I’d also want these errors to be observed in production, maybe that’s also possible with the logging setup

mhuebert18:07:39

Have to dig up plexus‘ blog post on this

lilactown19:07:38

I've experienced this before as well, and your gist was super helpful. Thanks!

🙂 4
mhuebert19:07:25

so, following plexus’s nice post (https://lambdaisland.com/blog) I found the four lines of code necessary to get goog logging to work

mhuebert19:07:49

but it’s not very useful

mhuebert19:07:10

no stacktrace or clue as to where the issue is

lilactown19:07:45

yeah, same experience here

lilactown19:07:52

I think adding the custom logging is much more useful

mhuebert19:07:57

FWIW

(ns ... 
  (:require [goog.debug.Console :as Console])
  (:import [goog.debug Console]))
(.setCapturing (Console.) true)
(Console/autoInstall)

mhuebert19:07:44

goog also has not figured out how to get its own code to work with DCE

😬 4
mhuebert19:07:22

(not that it’s big, but)

mhuebert19:07:19

oh: I spoke too soon, I am now seeing a debug stacktrace

mhuebert19:07:06

is it possible to set a global log level w/ goog.log?

mhuebert19:07:23

or is it only per logger

lilactown19:07:43

taoensso's timbre does this for us I think

mhuebert19:07:28

here is a reasonable default w glog:

(:require [goog.debug.Logger.Level :as Level]
            [goog.log :as glog])
(:import [goog.debug Console])

(.setCapturing (Console.) true)
(.setLevel (glog/getLogger "") Level/WARNING)

mhuebert19:07:57

i’ll also add that to the gist… it adds 1.5kb but presumably may be useful for other errors cropping up from goog stuff

dabrazhe09:07:12

when connecting on shadow nrepl port i am getting the clj repl. how do I start cljS repl from it these days?

thheller09:07:04

assuming you have the watch for the build already running you just switch to it

thheller09:07:13

(shadow.cljs.devtools.api/repl :the-build-id)

dabrazhe09:07:24

i am getting [:no-worker :the-build-id]

thheller09:07:41

that should be the actual id of your build obviously

dabrazhe09:07:05

i've started it as .. server start

dabrazhe09:07:13

where do i find the build ID

thheller09:07:23

your build config

thheller09:07:45

{:builds {:this-is-the-build-id {:target :browser ....}}}

thheller09:07:00

:app or whatever you have

thheller09:07:47

shadow-cljs.edn

dabrazhe09:07:15

should the watch be running or sever start is enouhg

thheller09:07:49

the watch needs to be running if you want a REPL for your build

thheller09:07:22

how you start the watch is up to you. either from the command line or from the CLJ REPL via (shadow.cljs.devtools.api/watch :the-build-id)

dabrazhe09:07:14

it's started, but..

cljs.user=>
[:selected :app]
1

No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.

dabrazhe09:07:33

i guess i am missing smth basic.

thheller09:07:27

yes. what build do you have? if its :target :browser you need to open the browser and load your JS

thheller09:07:46

if you just want a REPL to play with you can just run (shadow.cljs.devtools.api/browser-repl) or (shadow.cljs.devtools.api/node-repl)

thheller09:07:13

that'll just give you a REPL without being tied to a build

dabrazhe09:07:49

the build is node

:builds {:app {:target :node-library
                :exports {:handler server.main/handler}
                :output-dir "target"
                :output-to "target/main.js"}}}

thheller09:07:37

yeah that would require running the target/main.js via node or so

dabrazhe09:07:51

i guess the trick is to start the node repl, not the broswer : )

thheller09:07:52

just use node-repl

dabrazhe09:07:32

yes, it' s working! Thank you Thomas, you are a star!

thedavidmeister14:07:47

how do i point to something local for a dependency?

thedavidmeister14:07:54

or a specific github commit?

thheller14:07:13

for that you must use deps.edn

thedavidmeister14:07:26

thanks i'll have a look

thedavidmeister14:07:04

Exception in thread "main" java.io.FileNotFoundException: Could not locate shadow/cljs/devtools/cli__init.class, shadow/cljs/devtools/cli.clj or shadow/cljs/devtools/cli.cljc on classpath.

4
thheller15:07:32

assuming you configured deps.edn?

thheller15:07:47

then you need to add thheller/shadow-cljs to your dependencies

thedavidmeister15:07:35

@thheller in addition to or instead of npm install?

thheller15:07:59

shadow-cljs is two parts. the JS parts that do the CLI stuff and the JVM parts that do the actual compilation

👍 4
thheller15:07:09

so yes you need both

daviwil15:07:20

I don't see it explicitly mentioned in the User Guide, but is the :dump-core compiler option supposed to work in cljs builds? I'm finding that even when setting that to true, cljs.js/dump-core still returns nil

thheller15:07:05

:dump-core is not supported. if you need self-hosted support you should follow this https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html

daviwil15:07:45

excellent, thank you! I hadn't run across this post yet

jimmy17:07:56

I can’t get npx shadow-cljs watch ... with :http-root to work on any version of shadow-cljs later than 2.6.x. I tried a personal project, the re-frame example[1], and the quickstart browser example[2]. Every time I run them everything other the than index (js,css,etc) fails to load with a 404. I tried changing to the new format suggested by issue 436[3] and got the same behavior. There are no sym-links involved in any of this. I am on mac. I tried node versions 8 and 10, with no difference in behavior. The index.html is loading and making changes to it are reflect, but no other resources are loaded (in same directory or otherwise). Serving that folder with something like simple-http works perfectly fine. I am on mac os catalina, so that could be the issue. I can’t really follow the code for the dev server. I do know based on adding print statements to my personal project that the js and css files are ultimately making their way to the push state handler[4], where they are then turned in 404s. If there is any way I can help debug this issue I’d be happy to. I wanted to check on here first to make sure I’m not missing something obvious. [1] https://github.com/shadow-cljs/examples/tree/master/re-frame [2] https://github.com/shadow-cljs/quickstart-browser [3] https://github.com/thheller/shadow-cljs/issues/436 [4] https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/http/push_state.clj

thheller21:07:13

@jimmy what is your actual config? which version are you on? there are no issues I know of related to the dev http servers

jimmy22:07:11

All I did was take the quickstart above clone it and change the version to the latest. I then tried the last 5 or so versions. Tried 2.7.0. Still didn't work. Tried 2.6.0 and it worked.

lilactown22:07:55

@jimmy I cloned the shadow-cljs/examples repo, and ran the following commands:

cd shadow-examples/re-frame
npm i
npm i -D shadow-cljs # currently installs 2.8.40
npm run watch # shadow-cljs watch app
After letting the build complete, I am able to load both the compiled code and CSS

lilactown22:07:38

I am on macOS Mojave 10.14.4, so that might be relevant as you said

lilactown22:07:25

for clarity, I am able to see the build files loaded by going to http://localhost:8280

lilactown22:07:39

it looks like there may have been one or more changes to the dev server between 2.6 and 2.7. @jimmy could you try some of the intermediate versions?

lilactown22:07:56

it looks like a lot of changes occurred between 2.6.14 and 2.6.24 so you might start between those two versions

mhuebert18:07:59

well, found a way to listen for errors during module loading: https://gist-press.com/mhuebert/dfdf5dd94bbb944e995dc475c4421f4c I think it’s kind of crazy that ModuleManager’s default is to silently swallow errors. (I saw a comment in the source where they wonder if they should throw, so they have been thinking about this)

4