weavejester / hashp

A better "prn" for debugging
MIT License
442 stars 23 forks source link

Shadow-CLJS release builds will fail at runtime with hashp #13

Open filipesilva opened 3 years ago

filipesilva commented 3 years ago

Heya 👋

Following the instructions in https://github.com/weavejester/hashp#shadow-cljs, a release build (e.g. shadow-cljs release app) containing #p usage will fail at runtime due to missing namespaces.

/home/filipesilva/work/relemma/out/admin.js:280
"cljs.core.async.impl.ioc-helpers/t_cljs$core$async$impl$ioc_helpers212438")};return new yg(a,Id)}function Ag(a){try{var b=a[0];return b.a?b.a(a):b.call(null,a)}catch(c){if(c instanceof Object)throw b=c,rg(a[6]),b;throw c;}}function Cg(a,b){a=a[6];null!=b&&sg(a,b,zg(function(){return null}));rg(a);return a};function Dg(){var a=T.b(1,0)?null:1;return wg("number"===typeof a?new Yf(new Xf(Array(a)),a):a)}
                                                                                                                                                                                                 ^

ReferenceError: hashp is not defined
    at /home/filipesilva/work/relemma/out/admin.js:282:289
    at If.h.b (/home/filipesilva/work/relemma/out/admin.js:251:127)
    at Function.f [as a] (/home/filipesilva/work/relemma/out/admin.js:284:146)
    at Ag (/home/filipesilva/work/relemma/out/admin.js:280:142)
    at /home/filipesilva/work/relemma/out/admin.js:285:130
    at Immediate.hg (/home/filipesilva/work/relemma/out/admin.js:272:212)
    at processImmediate (internal/timers.js:439:21)

I understand that hashp is a debugging tool, my concern here is that leftover debugging code results in a broken build that does not fail compilation, and might not even fail on smoke tests since the failure will only occur when hitting the code path.

The only way I've found to prevent this situation is to set Shadow-CLJS to fail on release builds when there's undeclared var warnings:

{:dependencies [hashp "0.2.0"]
 :nrepl {:init-ns user}
 :builds {:app {:devtools {:preloads [hashp.core]}
                :release {:compiler-options {:warnings-as-errors #{:undeclared-var}}}}}}

This works because the build will emit the following warnings:

 variable zprint is undeclared
 Use of undeclared Var hashp.core/prefix
 Use of undeclared Var zprint.core/zprint-str
 Use of undeclared Var hashp.core/print-opts

Maybe there's a better way, but I don't know of it.

Shadow CLJS also mentions it doesn't support data readers in https://github.com/thheller/shadow-cljs/issues/272, and mentions it affects caching.

kovasap commented 2 years ago

+1, just ran into this problem myself. Although my use case is that I actually want to use #p in a release build.