metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.5k stars 211 forks source link

`pretty/reporter` doesn't report the function name on failed validations #779

Closed BrunoBonacci closed 1 year ago

BrunoBonacci commented 1 year ago

using [metosin/malli "0.8.4"]

see the following repl session

user> (ns user 
        (:require [malli.core :as m]
                  [malli.instrument :as mi]
                  [malli.dev :as dev]
                  [malli.dev.pretty :as pretty]))
nil
user> (defn plus [x y]
         (+ x y))
#'user/plus

user> (m/=> plus [:=> [:cat :int :int] :int])
..instrumented #'user/plus
user/plus

user> (dev/start! {:report (pretty/reporter)})
..instrumented #'user/plus
started instrumentation
nil

user> (plus 1 "2")

-- Schema Error ------------------------------------------------ form-init7954450409628955716:739 --

Invalid function arguments:

  [1 "2"]

Input Schema:

  [:cat :int :int]

Errors:

  {:in [1], :message "should be an integer", :path [1], :schema :int, :value "2"}

More information:

  https://cljdoc.org/d/metosin/malli/CURRENT/doc/function-schemas

----------------------------------------------------------------------------------------------------
user> 

As you can see from the error the function name is not present anywhere, and while this is obvious in this little example, when the error is nested, is incredibly hard to find which function failed the validation.

I think instead of form-init7954450409628955716:739 the fully qualified function name should be displayed, the name in the previous example is available in the registry.

user> @@#'m/-function-schemas*
{:clj
  {user
  {plus {:schema [:=> [:cat :int :int] :int], :ns user, :name plus}}}
dvingo commented 1 year ago

Hi @BrunoBonacci the function Var (symbol naming the var) is printed in latest version of malli (0.9.2): https://github.com/metosin/malli/blob/55d4888c15df9f6affb67f34fcdea449a3c11d6d/src/malli/dev/pretty.cljc#L46

BrunoBonacci commented 1 year ago

Oh nice, I'll try it out.

BrunoBonacci commented 1 year ago

I've tried with the 0.9.2 version and it works as you said, thanks

sample output

-- Schema Error ------------------------------------------------------------------- Compiler:7194 --

Invalid function arguments:

  [1 "2"]

Function Var:

  user/plus

Input Schema:

  [:cat :int :int]

Errors:

  {:in [1], :message "should be an integer", :path [1], :schema :int, :value "2"}

More information:

  https://cljdoc.org/d/metosin/malli/CURRENT/doc/function-schemas

----------------------------------------------------------------------------------------------------