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

Error printing return value of try monad in REPL #232

Open
mwelt opened this issue May 14, 2019 · 3 comments
Open

Error printing return value of try monad in REPL #232

mwelt opened this issue May 14, 2019 · 3 comments

Comments

@mwelt
Copy link

mwelt commented May 14, 2019

Using cats in CIDER + nREPL yields:

;; CIDER 0.22.0snapshot (package: 20190326.1752), nREPL 0.6.0
;; Clojure 1.10.0, Java 1.8.0_201

user> (require '[cats.monad.exception :as exc])
(exc/try-on 1)
nilError printing return value (IllegalArgumentException) at clojure.lang.MultiFn/findAndCacheBestMethod (MultiFn.java:179).
Multiple methods in multimethod 'simple-dispatch' match dispatch value: class cats.monad.exception.Success -> interface clojure.lang.IDeref and interface clojure.lang.IPersistentMap, and neither is preferred
@alexanderjamesking
Copy link

I see this too:

user> (require '[cats.monad.either :as either])
nil
user> (either/left "foo")
IllegalArgumentException Multiple methods in multimethod 'simple-dispatch' match dispatch value: class cats.monad.either.Left -> interface clojure.lang.IPersistentMap and interface clojure.lang.IDeref, and neither is preferred  clojure.lang.MultiFn.findAndCacheBestMethod (MultiFn.java:178)
user> (either/right "foo")
IllegalArgumentException Multiple methods in multimethod 'simple-dispatch' match dispatch value: class cats.monad.either.Right -> interface clojure.lang.IPersistentMap and interface clojure.lang.IDeref, and neither is preferred  clojure.lang.MultiFn.findAndCacheBestMethod (MultiFn.java:178)

@mwelt
Copy link
Author

mwelt commented May 17, 2019

After a little more trial and error if found the following.

It works if you dereference the values with "@" like so:

user> @(exc/try-on 1)
1
user> @(exc/try-on (/ 1 0))
ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:163)

I guess its intended that way.

@dchelimsky
Copy link
Contributor

This is a side-effect of adding IDeref to a defrecord in order to support ref-like syntax for unwrapping monadic values.

I don't know if this is a good solution, but I was able to get around it like this:

user> (defmethod clojure.pprint/simple-dispatch cats.monad.exception.Failure [f]
  (pr f))
#multifn[simple-dispatch 0x12668380]
user> @(#'cats.monad.exception/->Failure (ex-info "oops" {}))
Execution error (ExceptionInfo) at user/eval15705 (form-init5393967084257662022.clj:136).
oops

This is what printed to the *cider-error* buffer:

1. Unhandled clojure.lang.ExceptionInfo
   oops
   {}
                      REPL:  136  user/eval15705
                      REPL:    1  user/eval15705
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
                  AFn.java:   22  clojure.lang.AFn/run
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  834  java.lang.Thread/run

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

3 participants