<< Back to previous view

[CLJS-581] Advanced compiler renames console.groupCollapsed. Created: 30/Aug/13  Updated: 19/Nov/13  Resolved: 19/Nov/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Johnny Brown Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None



In the lein-cljsbuild simple sample app, I enabled advanced compilation and changed the example.hello namespace to the following:

(ns example.hello)

;; taken unchanged from io.pedestal.app.util.platform
(defn log-exceptions [f & args]
  (try (apply f args)
       (catch js/Error e
         (.groupCollapsed js/console "Caught exception" e)
         (.log js/console "Was applying function\n" f)
         (.log js/console "With arguments" (pr-str args))
         (.log js/console "Re-throwing error...")
         (.groupEnd js/console)
         (throw e))))

(defn ^:export greet [name]
     (js/alert (str "Hello " name))
     (throw (js/Error "whatever")))))

Then ran lein cljsbuild once, loaded the project in my browser (google chrome) and in the browser call example.hello.greet("me")

This results in an error, but not the one we expect. Instead we get TypeError: Object #<Console> has no method 'wb'.

This is because the log-exceptions function was compiled to the following. Notice how console.groupCollapsed has been renamed to console.wb.

function mf(a, b) {
  try {
    return $b.b(a, b)
  }catch(c) {
    c instanceof Error && (console.wb("Caught exception", c), console.log("Was applying function\n", a), console.log("With arguments", lf.j(P([b], 0))), console.log("Re-throwing error..."), console.groupEnd()), e(c)

I did a little more digging, and found this recent commit in the google closure history. It adds an extern to the list of default externs for groupCollapsed. It's pretty new (Jun 7) so presumably the clojurescript compiler is still using an older version.

I think all that needs to be done is to update the version of closure used?

As a workaround, add the two lines below to your externs file.

function Console() {};
Console.prototype.groupCollapsed = function(var_args) {};

Comment by David Nolen [ 30/Aug/13 7:13 PM ]

We could probably track Google Closure more closely, but we don't as this usually requires a considerable amount of testing to make sure that things don't break. We also need to make our own release of Google Closure since we depend on third party libraries. Stuart Sierra is more or less in charge of this process. We'll probably do another bump again soon but there's no rush as this particular issue is easily worked around.

Comment by David Nolen [ 19/Nov/13 9:22 PM ]

this can be worked around by supplying an externs file.

Generated at Sat Jan 20 03:50:50 CST 2018 using JIRA 4.4#649-r158309.