Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class becomes Symbol when going through str and read-string #34

Open
terjedahl opened this issue Apr 28, 2017 · 0 comments
Open

Class becomes Symbol when going through str and read-string #34

terjedahl opened this issue Apr 28, 2017 · 0 comments

Comments

@terjedahl
Copy link

I would like to get the stacktrace from an nREPL session using clj-stacktrace's parse-exception.
I would get it back as a String, which I could then apply read-string to and either use as I need, or pass on to pst-str.

However, when the parsed structure is converted to a String and then back again, the value for the top level :class goes from Class to Symbol, which then causes an exception.

This works:
(try (/ 0) (catch Exception e (-> e parse-exception pst-str)))

This does not work:
(try (/ 0) (catch Exception e (-> e parse-exception str read-string pst-str)))

It gives the exception:

ClassCastException clojure.lang.Symbol cannot be cast to java.lang.Class  clj-stacktrace.repl/pst-class-on (repl.clj:59)

I can of course apply this work-around (I convert the symbol to a class):

(try (/ 0) (catch Exception e (-> e parse-exception str read-string (update-in [:class] class) pst-str)))

Suggested fix - alternative 1:
Remove the type-hint in line 58, and to a type-test and conversion or similar before building the pst-line in lin 59.

Suggested fix - alternative 2:
Have parse-exception return a String-value for :class - in the same way as the :class value is a String in the stacktrace-elements.

I would prefer alternative 2, as it would be more consistent in general. On the downside, it might break something for other users, assuming the expect a Class, but now get a String.

Either way, would you like me to submit a pull-request for one of the fix-alternatives?
If so, which one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant