malli
malli copied to clipboard
Malli ExceptionInfo is not enough to figure out where the exception occurred
- malli version: 0.13.0
The following is the test example in clj.
;; malli-test/main.clj
(ns malli-test.main
(:require [malli.core :as m]
[malli.instrument :as mi]))
(m/=> power [:=> [:cat :int] [:int {:max 6}]])
(defn power [x] (* x x))
(power 6)
; => 36
;; instrument all registered vars
(mi/instrument!)
(power "6")
;; Error output in REPL
Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:138).
:malli.core/invalid-input
I cannot figure out where the exception occurred.
The following is the test example in cljs by using shadow-cljs.
;; malli_test/main.cljs
(ns malli-test.main
(:require [malli.core :as m]
[malli.instrument :as mi]))
(m/=> power [:=> [:cat :int] [:int {:max 6}]])
(defn power [x] (* x x))
(mi/instrument!)
(power "6")
;; Chrome console output
..instrumented malli-test.main/power
cljs$core$ExceptionInfo {message: ':malli.core/invalid-input', data: {…}, cause: null, name: 'Error', description: undefined, …}
cause : null
columnNumber : undefined
data : cljs.core/PersistentArrayMap [count: 3]
description : undefined
fileName : undefined
lineNumber : undefined
message : ":malli.core/invalid-input"
name : "Error"
number : undefined
stack : "Error: :malli.core/invalid-input\n at new cljs$core$ExceptionInfo (file:///js/cljs-runtime/cljs.core.js:37369:10)\n at Function.eval [as cljs$core$IFn$_invoke$arity$3] (file:///js/cljs-runtime/cljs.core.js:37430:9)\n at Function.eval [as cljs$core$IFn$_invoke$arity$2] (file:///js/cljs-runtime/cljs.core.js:37426:26)\n at Function.eval [as cljs$core$IFn$_invoke$arity$2] (file:///js/cljs-runtime/malli.core.js:1253:26)\n at Function.eval [as cljs$core$IFn$_invoke$arity$2] (file:///js/cljs-runtime/malli.core.js:1280:29)\n at Object.G__28317__delegate (file:///js/cljs-runtime/malli.core.js:12285:48)\n at Object.G__28317 (file:///js/cljs-runtime/malli.core.js:12310:27)\n at eval (file:///js/cljs-runtime/malli_test.main.js:8:17)\n at eval (<anonymous>)\n at goog.globalEval (file:///Users/philos/work/malli-test/resources/public/js/main.js:434:11)"
I cannot figure out where the exception occurred as well.
How can I figure out where the exception occurred?
For clojure you can use https://clojuredocs.org/clojure.core/*e
For cljs it looks like you don't have cljs devtools installed, you can find instructions on getting setup here:
https://github.com/metosin/malli/blob/master/docs/clojurescript-function-instrumentation.md
with details on how to find the source of your error in your codebase.
How does this look with the new development mode?