Fork me on GitHub
#shadow-cljs
<
2023-02-02
>
Lycheese09:02:38

In my init-fn I try to disable logging like this:

(ns app.entry
  (:require
   [app.core :as core]))

(defn init []
  (js/console.log "Initializing app!")

  ;; (when-not ^boolean js/goog.DEBUG)
  (set! *print-fn* (fn [& _]))

  (js/console.log "This shouldn't appear.")

  ,,,,)
But it never works. It does if I eval the set! call manually though. Any ideas on what might be causing this?

thheller09:02:04

js/console.log is not related to printing in any way. that is a browser feature.

thheller09:02:02

that is to say js/console.log is not affected by *print-fn*, prn or others use *print-fn* which defaults to using js/console.log

thheller09:02:18

(js/console.log "This shouldn't appear.") so this will always appear

thheller09:02:26

(println "This shouldn't appear.") won't

Lycheese09:02:11

Ooooooh. That makes sense. So I should replace every call to js/console.log with println?

Lycheese09:02:44

Wait but then that doesn't appear in the browser console. Hmmm. Not println but prn facepalm Ah. (set! js/console.log (fn [& _])) does the trick

Lycheese09:02:01

Thanks 🙂

Drew Verlee18:02:32

My goal is to have the same level of stack trace information in shadow development mode locally as i get from the logrocket (a screen capture service). I uploaded my source maps to them, and it now i'm getting almost the ideal set of information. See in LR, the stacktrace tells me the file where the issue happened (see screenshot): js/cljs-runtime/centriq_web.admin.js:428 but in my local browser i get the location in the cljs file, which is way better. e.g (admin.cljs:579:36). Is there a way in general to do this? My understanding is that we compile cljs to js to minified js, the source map is for the second compile step. Are people able to trace it all the way back to the first one?

thheller18:02:25

I'm not sure I understand your question?

thheller18:02:33

source maps map JS code back to CLJS, that is correct

thheller18:02:40

they are generated during compilation

thheller18:02:03

by default they are disabled for release builds, you can enable them by setting :compiler-options {:source-map true}

thheller18:02:19

I'm not quite sure what the point of logrocket for development is?

Drew Verlee18:02:22

logrocket is pointless for local development on my computer. It captures user sessions in production. If the encounter a js error, without further information (source maps) for us, the error it gives us is compressed js. I attempted to give LR source maps according to there instructions, and now it tells me the JS file where the error happened, but i'm hoping i can get it to tell me the cljs file and line number.

thheller18:02:01

which source map did you give them? since the above is at most from a development build?

thheller18:02:19

it is not from a release build. I assume you are not serving your users development builds?

Drew Verlee18:02:29

> it is not from a release build. I assume you are not serving your users development builds? I'm not. I did a release then uploaded that source map. then i started my shadow server locally and LR is tracking that session. Likely i need to do a release, upload that, then run that release locally.

thheller18:02:07

I'm still lost how this all fits together

thheller18:02:27

> then i started my shadow server locally and LR is tracking that session.

thheller18:02:40

why is LR involved in development?

thheller18:02:14

you generate a release build. it generates a matching .map file, that ONLY matches that JS output.

thheller18:02:26

if you run any other JS, it won't match and give you now proper results

thheller18:02:44

so then running the dev build locally against those maps is pointless

thheller18:02:58

so I'm still unsure what you are trying to do exactly

Drew Verlee18:02:06

Thanks for the help. This largely isn't a shadow question. I was more asking if people using error reporting tools for production apps were able to get those tools to report the exact line the error happened at in the original cljs file. If everyone said no then i would assume there was some huge obstacle there. What i want is to log into logrocket, view a production user session, and if they had a js error, have log rocket tell me where in the cljs file the issue happened. If you don't upload sourcemaps, what it tells you is the location in the js minified file, because thats all it has. In my attempt to develop on this feature, i'm trying to use a locally running version of the app on my computer. LR has no probably tracking that session, just like i can track any session. I think my mistake is thinking the release build would be identical to what the shadow server build was producing. I should just run the release locally and see if its working as expected. The alternative is that i configure LR, upload the assets, and wait for a staging build. That has like a 15 minute turn around time. so if for some reason the configuration is wrong, it takes a long time to adjust.

thheller18:02:12

what you can and should do is version your javascript

thheller18:02:18

and you need the EXACT output of the exact build, not a different build. the same map and matching JS file

👍 2
thheller18:02:33

yes, you cannot just run release locally again. that will give you a different build

thheller18:02:50

if you version it from the beginning you'll have an easier time figuring out which JS caused the problem

thheller18:02:58

and then just download it yourself and use it

thheller18:02:03

do not do a rebuild

thheller18:02:22

so you'll have a +

thheller18:02:02

if the files match you should get proper traces

Drew Verlee18:02:18

that makes sense, I think your right that would be necessary for this to work properly. If done correct, is it possible to get the same error report we get locally from an error that happened to a user using the minified release?

thheller18:02:24

I don't know what you mean by that

thheller18:02:30

if you use the same files you get the same error

thheller18:02:56

if you figure out what it was in the first place 😛

Drew Verlee18:02:43

Let me try to explain again, this is useful for me because its possible i'm barking up the wrong tree. Logrocket downloads the js file from a user session that we have allowed it to track, If an js error happened in that session, LR will show where in the js file it downloaded that error was. In a minified file that looks like this:

adow$provide[0]=function(T,I,ia,ha){var E=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;ia.exports=function(){try{if(!Object.assign)return!1;var h=new String("abc");h[5]="de";if("5"===Object.getOwnPropertyNames(h)[0])return!1;var k=

Drew Verlee18:02:15

the line number in the minified file, and the accompanying text (above) isn't useful for debugging the issue. So i need to unminify it, and then map it back to the cljs. I assume that's possible, but i haven't read a tutorial on it, i haven't seen it done, and yet it would seem like an obvious thing to want. If this works out, maybe ill write the tutorial, then discover there are like 10 of them already, i just failed to find them.

thheller18:02:36

there is your mistake

thheller18:02:39

you don't do any of thjat

thheller18:02:10

assuming the code above sits in a app.v1.js file and you have uploaded a app.v1.js.map file to LR, you should get proper stacktraces already

thheller18:02:15

thats it. nothing else to do

thheller18:02:41

> So i need to unminify it, and then map it back to the cljs.

thheller18:02:46

that is literally what the source map is for

thheller18:02:10

you don't do anything, it just works

thheller18:02:29

only problem is if files don't match

thheller18:02:42

or you try a development build and somehow map that to a release build

thheller18:02:45

that will never work

Drew Verlee18:02:20

I agree. My hope was that the only thing i had to do was upload the source maps. Thanks a ton, i'm pretty confident on what i have to do now.

thheller18:02:36

the screenshot you posted above was some development build

thheller18:02:53

since a release build doesn't contain any cljs-runtime/ code

thheller18:02:13

the reason you need versioning is to ensure the files match

thheller18:02:28

if you run a shadow-cljs release app and produce just a app.js

thheller18:02:39

and then do that again, there is no way to map anything

thheller18:02:46

since it won't be clear what code was used

Drew Verlee18:02:22

yep, total makes sense. 🙂 Thanks for your patience and support.