English 中文(简体)
Obtaining stack traces in ClojureScript
原标题:

In my ClojureScript programs running in FireFox 5.0 on Ubuntu 10.04.1 LTS, I get a single cryptic line when an exception is thrown.

Error: No protocol method ISeqable.-seq defined for type object: [object Object] when calling method: [nsIDOMEventListener::handleEvent]

The "-seq" bit seems strange to me and I have searched the generated javascript files for it and not found it.

I hope I am not missing something entirely obvious, but how do I get a stack trace of the exception thrown? How are you debugging your scripts?

问题回答

Unfortunately stack traces from errors rely on browser support. Most (all?) browsers will allow you to access a canned version of the stack trace (usually the top 10 elements, iirc) as a string by dereferencing the stack field, so you could do something like this:

(try ...throws...
    (catch js/Error e
        (.log js/console (.-stack e))))

However, string stack traces aren t much fun, you can t click them to take you to the source. Better is printing the exception directory to the javascript console (if it s available) to print stack traces with clickable links. E.g.

(try ...throws...
    (catch js/Error e
        (.log js/console e)))

At least in chrome, this only works if the javascript console was open when the error was thrown. This is great for debugging, but less useful when the error was unexpected.

The javascript console objects provided by most browsers have lots of useful functions that you can use from clojurescript. If you want to get helpful line numbers though, you probably want to write a couple of macros to inject the code to print to the console, otherwise all your line numbers will point to your print function.

Looks like you are passing a Javascript object to a Clojurescript function which expects a Clojure sequence. Try (my-function (js->clj my-thing)) edit: or, I m guessing you re using (.strobj) where you don t need to





相关问题
Obtaining stack traces in ClojureScript

In my ClojureScript programs running in FireFox 5.0 on Ubuntu 10.04.1 LTS, I get a single cryptic line when an exception is thrown. Error: No protocol method ISeqable.-seq defined for type object: [...

Workarounds for using ClojureScript with the OpenJDK?

I ve been working on a project with Clojure and Noir and I m enjoying the free hosting on Heroku s cedar stack. I ve recently added some UI work in ClojureScript to find that it works locally but ...

Javascript interop assignment in Clojurescript

Dumb question: how do I do Javascript assignment in Clojurescript ? I m using a Javascript lib and need to set the value of an object s field like obj.this=that; - I don t know Javascript so maybe ...

Javascript as debuggable bytecode

There is a rise in languages that output javascript, such as CoffeeScript and ClojureScript. Since javascript will not be going away anytime soon, I presume this pattern of development will continue. ...

How do I add my own JavaScript libs to ClojureScript?

I want to write a Google Chrome extension, using ClojureScript. With ClojureScript I can use all the Google Closure libs, but afaik access to the Chrome browser is not included in those libs. So I ...

Any clojurescript tutorials? [closed]

Are there already some good tutorial on ClojureScript? I would like to try it out, but don t know where to start exactly.

How to use ClojureScript practically? [closed]

I am not getting the idea of ClojureScript. For example, I am writing a web application, and I need to write some javascript. Should I use ClojureScript which will generate the javascript for me? ...

热门标签