core.async

(CLJS) ClojureScript `catch :default` in `go` fails with non-`js/Error` classes

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

In ClojureScript, `(catch :default e ...) in a `go` block fails with non-`js/Error` classes. That is, throwing e.g. a number, a String, etc. fails (not that this is good practice anyway, but still). I came upon this while porting Slingshot (scgilardi/slingshot) to CLJS.

Given the following tests:

```
(defn test0
"Prints 'Error: nil'."
[]
(go (println "Error:"
(<! (go (throw (js/Error.)))))))

(defn test1
"Prints 'Error: #object[Error Error]'."
[]
(go (println "Error:"
(<! (go (try (throw (js/Error.))
(catch :default e e)))))))

(defn test2
"Doesn't print anything in addition to the console error
msg. Chrome says 'Uncaught 123'."
[]
(go (println "Error:"
(<! (go (try (throw 123)
(catch :default e e)))))))
```

`test2` should print 'Error: 123', but doesn't.

(As a sidenote, shouldn't `test0` return the thrown js/Error instead of printing to the console that there was an uncaught error and returning nil?)

Activity

Hide
Alex Gunnarson added a comment -

Sorry, I should have specified that this is for ClojureScript version 1.9.93 and core.async version 0.2.385. Also forgive the lack of markup.

Show
Alex Gunnarson added a comment - Sorry, I should have specified that this is for ClojureScript version 1.9.93 and core.async version 0.2.385. Also forgive the lack of markup.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: