Attempt at making debugging CLJS a little easier

170 views
Skip to first unread message

Thomas Heller

unread,
Feb 17, 2013, 12:17:32 PM2/17/13
to clojur...@googlegroups.com
Hey,

I'm beginning to amass a fairly substantial CLJS code base and while most things just works great, debugging Code is way too hard. Main problem is that stack traces just arent very helpful, just figuring out in which function you actually are is sometimes the hardest part.

So I created a .patch (https://gist.github.com/thheller/4972200) which will turn

Uncaught Error: No protocol method IElement.-to-dom defined for type null:
missing_protocol
(anonymous function)
_to_dom
append__2
append
append__1
append
popup_open__delegate
popup_open
list_objects
dom_event_handler
goog.events.Listener.handleEvent
goog.events.fireListener
goog.events.handleBrowserEvent_
(anonymous function)


into


Uncaught Error: No protocol method IElement.-to-dom defined for type null:
fn_cljs_DOT_core_SLASH_missing_protocol_78
(anonymous function)
fn_thheller_DOT_web_DOT_dom_SLASH__to_dom_89
fn_thheller_DOT_web_DOT_dom_SLASH_append_122__2
fn_thheller_DOT_web_DOT_dom_SLASH_append_122
fn_thheller_DOT_web_DOT_dom_SLASH_append_122__1
fn_thheller_DOT_web_DOT_dom_SLASH_append_122
fn_thheller_DOT_debug_SLASH_popup_open_108__delegate
fn_thheller_DOT_debug_SLASH_popup_open_108
fn_thheller_DOT_debug_SLASH_list_objects_121
fn_thheller_DOT_object_SLASH_dom_event_handler_169
goog.events.Listener.handleEvent
goog.events.fireListener
goog.events.handleBrowserEvent_
(anonymous function)


Not the best example, I forgot which stacktrace actually set me out to do this, but as u can see every fn is now fully qualified. Format may be optimized but its basically "fn_[ns]/[fn name]_[line]".

It compiles fine but produces a little more code since the names can get quite long. Files get a little larger, but {:optimiziations :advanced} takes care of that and AFAICT nothing breaks. Tests pass and my code works. ;)

Is this something anyone would be interested in? Should I open a Ticket?

Regards,
/thomas


PS: If you are using lein-cljsbuild and want a quick test do this:

cd your-project
mkdir lib
cd lib
git clone git://github.com/thheller/clojurescript.git
cd clojurescript
git co debug-friendly-fn-names
cd ..
cd ..

edit project.clj and add ["lib/clojurescript/src/clj" "lib/clojurescript/src/cljs"] to the root :source-paths (not the cljsbuild source paths)

lein cljsbuild clean
lein cljsbuild once

and test your code

Valentin Golev

unread,
Feb 18, 2013, 9:16:44 AM2/18/13
to clojur...@googlegroups.com
This is really great, thank you!

Wondering if source maps would be able to adress this kind of problem.

By the way, in my opinion, exceptions like "undefined has no method call()" are the real plague...

David Nolen

unread,
Feb 18, 2013, 10:05:19 AM2/18/13
to clojur...@googlegroups.com
Go ahead and create a ticket and attach this patch, I'll review it more closely when I get the chance.

Thanks!
David



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript?hl=en.



David Nolen

unread,
Feb 18, 2013, 10:07:00 AM2/18/13
to clojur...@googlegroups.com
I think source maps will be a big improvement to the ClojureScript debugging story.

The undefined call errors - I'm not sure how we can help there - do you have some ideas?


Thomas Heller

unread,
Feb 18, 2013, 12:08:37 PM2/18/13
to clojur...@googlegroups.com
Haven't look into source maps closely yet, debugging javascript never exited the print/reload realm for me (yet). So I focused on that.

I created a little cljs snippet which pretty prints functions. Since they usually just dump the source all over you and usually there is no simple way to identify a cljs function via its js source. Although I got kinda good at that. ;)

Anyways gist is here https://gist.github.com/thheller/4972200


Example:

(.log js/console (pr-str name))

=>

#<function fn_cljs_DOT_core_SLASH_name_5876(x) {
if(cljs.core.string_QMARK_.call(null, x)) {
return x
}else {
if(cljs.core.truth_(function() {
var or__3966__auto__ = cljs.core.keyword_QMARK_.call(null, x);
if(or__3966__auto__) {
return or__3966__auto__
}else {
return cljs.core.symbol_QMARK_.call(null, x)
}
}())) {
var i = x.lastIndexOf("/", x.length - 2);
if(i < 0) {
return cljs.core.subs.call(null, x, 2)
}else {
return cljs.core.subs.call(null, x, i + 1)
}
}else {
if("\ufdd0:else") {
throw new Error([cljs.core.str("Doesn't support name: "), cljs.core.str(x)].join(""));
}else {
return null
}
}
}
}>

vs: #<function cljs.core/name line:5876>

I will create a Ticket now.

Cheers,
/thomas

Thomas Heller

unread,
Feb 18, 2013, 12:24:14 PM2/18/13
to clojur...@googlegroups.com
Ticket created: http://dev.clojure.org/jira/browse/CLJS-474


PS: Did my CA arrive yet? Sent it last Monday.

David Nolen

unread,
Feb 18, 2013, 1:11:48 PM2/18/13
to clojur...@googlegroups.com
Thanks! 

When your CA arrives this page will get updated: http://clojure.org/contributing


On Mon, Feb 18, 2013 at 12:24 PM, Thomas Heller <th.h...@gmail.com> wrote:
Ticket created: http://dev.clojure.org/jira/browse/CLJS-474


PS: Did my CA arrive yet? Sent it last Monday.
Reply all
Reply to author
Forward
0 new messages