This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-05
Channels
- # aleph (6)
- # announcements (2)
- # babashka (8)
- # beginners (121)
- # calva (7)
- # cider (7)
- # clj-kondo (25)
- # clojure (167)
- # clojure-android (1)
- # clojure-italy (1)
- # clojure-sweden (1)
- # clojuredesign-podcast (2)
- # clojurescript (11)
- # community-development (33)
- # cursive (23)
- # data-science (1)
- # datascript (11)
- # datomic (7)
- # emacs (12)
- # events (1)
- # fulcro (15)
- # graalvm (3)
- # hoplon (1)
- # instaparse (1)
- # malli (12)
- # off-topic (1)
- # planck (3)
- # re-frame (5)
- # shadow-cljs (61)
- # test-check (2)
I could repro the behavior tianshu describes, and documented it in https://github.com/nedap/speced.def/issues/100#issuecomment-570865803 . It seems pretty unfortunate that when using a standard mechanism such as ex-info
, error reporting will become drastically worse, if the error happened on load.
Needless to say there are many cljs libs that can throw a ex-info at any point. i.e. this is not specific to my library.
@ thheller - are you 100% sure this is not something shadow-cljs can handle?
Otherwise, it'd seem worth it to create an issue in the cljs compiler, or such.
@vemv the issue is fixed by setting :devtools {:loader-mode :script}
in your build config
I got that point, but given :eval is the default, people can get a bad experience by default if using libraries such as mine Also, this seems an easy-to-forget intricacy
well the problem is in throwing exceptions at load time. that is never good. with eval the source maps are likely loaded differently and maybe the browser then has trouble dealing with the stacktraces
I really do not know. I could also just not catch any exceptions but that confused people more in the past
> that is never good. it is good if you are checking :pre and :post conditions, or similar mechanisms (spec-related solutions) I do not have an opinion on the right solution (for one thing I am unfamiliar with many compiler or shadow-cljs intricacies), but I'd like to point out that this is a reasonable problem to have. It's not urgent for me either, but I'd be happy if this was tracked in the right place (shadow-cljs or clojurescript).
the way I see it its a trade-off. faster loading via eval or slower loading but accurate errors during loading
as far as I can tell runtime makes no difference its just the load time that is problematic
I don't know what to do either. errors during load are problematic anyways since the program cannot continue after it. it gets into an undefined state so you have to reload the page anyways
> as far as I can tell runtime makes no difference its just the load time that is problematic scienced it myself, correct :)
> I don't know what to do either. errors during load are problematic anyways since the program cannot continue after it. it gets into an undefined state so you have to reload the page anyways
I can see how there could be different programmer preferences around this. Personally I have no problem whatsoever with hitting Cmd + R
if my program was so broken that it threw an exception on init.
Maybe worth considering - document :script and :eval? Would be nice if programmers were aware of these tradeoffs upfront.
At the same time, the root of the problem seems to lie in the js/Error
<-> ex-info
difference. By intution, there shouldn't be one. Would be interesting to determine what component is at fault (shadow, the compiler, etc)
shadow or the compiler isn't involved in this. it can only be the way ex-info is implemented
but it may just be a restriction of the javascript runtime that it only supports stacktraces for regular js/Error
until it had a change to load the source maps and stuff
alright! thanks for the clarification. > you can try subclassing Error and see if you can get it to work yes, I did try changing the error being thrown in my lib https://gist.github.com/vemv/e9a7534a5bc7f277395add3e7c23a291 , with success. However, since many things can throw ex-info at any point, probably I won't end up changing my thrown exceptions. Would not be a 100% solution. documenting the loader modes as mentioned might do the trick.
the use case is: in a cljs app, I add 'spec checking' to defns somehow. could be :pre or instrumentation If for any reason (like programmer error) the specs fail, an error will be thrown during load time. seems a quite likely possibility regardless of the specific chosen 'spec checking' library
from the stacktrace it looks like its your :init-fn
call which is the LAST thing during load time
(defn init [] (js/setTimeout foo 0))
is interesting, however I can't/shouldn't control how consumers of my library structure their applications
Documenting this intricacy seems far leaner/cleaner than suggesting workarounds or doing a best-effort approach to replacing ex-info -> js/Error everywhere. Don't you agree?
another thing I notice is that eval code in the repl facing the same problem. I can only get the meaningful error stack with js/Error.
I am trying to import TextField
from Material-UI. I am requiring using following code
(:require ["@material-ui/core/TextField" :default TextField])
However the symbol TextField
is undefined and it shows following error:
TypeError: Cannot read property 'default' of undefined
at eval (eval at shadow$cljs$devtools$client$browser$global_eval (), <anonymous>:1:55)
at eval (<anonymous>)
at Object.shadow$cljs$devtools$client$browser$global_eval [as global_eval] ()
at
at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] ()
at Object.shadow$cljs$devtools$client$browser$repl_invoke [as repl_invoke] ()
at shadow$cljs$devtools$client$browser$handle_message ()
at
at Object.shadow$cljs$devtools$client$env$process_next_BANG_ [as process_next_BANG_] ()
at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] ()
Please could you help me to figure this out.@kamila.herkova try shadow-cljs browser-repl
and (require '["@material-ui/core/TextField" :as x])
then x
or (js/console.dir x)
or so
After running x
it outputs this:
== JS EXCEPTION ==============================
ENCODING FAILED, check host console ==============================================
@kamila.herkova that means it can't print the object. try (js/console.dir x)
or (js/console.log x)
After running (js/console.dir x)
it returns nil
.
@kamila.herkova Does it print nil
in the developer tools js console?
In browser console this is returned:
Object
default: [Exception: TypeError: Cannot read property 'default' of undefined at Object.get [as default] (node_modules/@material-ui/core/TextField/index.js:1:336) at Object.invokeGetter (<anonymous>:1:142)]
__esModule: true
get default: ƒ ()
length: 0
name: "get"
arguments: null
caller: null
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: index.js:11
[[Scopes]]: Scopes[2]
__proto__: Object
so (require '["@material-ui/core/TextField" :default TextField])
and TextField
should be working fine
although it is weird that it is showing `default: [Exception: TypeError: Cannot read property 'default' of undefined at Object.get [as default] (node_modules/@material-ui/core/TextField/index.js:1:336) at Object.invokeGetter (<anonymous>:1:142)] ` for you
The problem is that this is the printout after running (require '["@material-ui/core/TextField" :default TextField])
.
just inspect it in the console. react uses js/Symbol and those aren't printable by default
This a minimal example of code where the problem occurs:
(ns project.text-field
(:require ["@material-ui/core/TextField" :default TextField]))
(defn text-field []
(js/console.log TextField)
[:div]
And the following stacktrace:@kamila.herkova can't tell what isRequired
is supposed to be but it might be caused by a dependency conflict. thats not so easy to debug unfortunately. for me it works in an empty test project so that makes dependency conflict more likely