Attempt at making debugging CLJS a little easier

Showing 1-7 of 7 messages
Attempt at making debugging CLJS a little easier Thomas Heller 2/17/13 9:17 AM
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

Attempt at making debugging CLJS a little easier Valentin Golev 2/18/13 6:16 AM
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...

Re: [ClojureScript] Attempt at making debugging CLJS a little easier David Nolen 2/18/13 7:05 AM
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.



Re: [ClojureScript] Attempt at making debugging CLJS a little easier David Nolen 2/18/13 7:07 AM
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?



--
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.



Re: [ClojureScript] Attempt at making debugging CLJS a little easier Thomas Heller 2/18/13 9:08 AM
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

Re: [ClojureScript] Attempt at making debugging CLJS a little easier Thomas Heller 2/18/13 9:24 AM
Ticket created: http://dev.clojure.org/jira/browse/CLJS-474


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

Re: [ClojureScript] Attempt at making debugging CLJS a little easier David Nolen 2/18/13 10:11 AM
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.

--
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.