Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 210
Synk Avatar asked Oct 05 '11 16:10

Synk


People also ask

How do I access stack trace?

Accessing Stack Traces with the Thread Class You can obtain a stack trace from a thread – by calling the getStackTrace method on that Thread instance. This invocation returns an array of StackTraceElement, from which details about stack frames of the thread can be extracted.

Where is stack trace in developer console?

If you go to set log panels and select "Execution Stack" and "Execution Log", it should bring up a stack trace panel next to the standard log panel. Clicking any line in the Log Panel will load up the stack for that line.

What is stack trace data?

What Does Stack Trace Mean? A stack trace is a report that provides information about program subroutines. It is commonly used for certain kinds of debugging, where a stack trace can help software engineers figure out where a problem lies or how various subroutines work together during execution.

What is stack trace in SQL?

In computing, a stack trace (also called stack backtrace or stack traceback) is a report of the active stack frames at a certain point in time during the execution of a program.


2 Answers

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.

like image 147
Stephen Nelson Avatar answered Oct 02 '22 05:10

Stephen Nelson


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

like image 24
Hendekagon Avatar answered Oct 02 '22 07:10

Hendekagon