由于创建了一个 Schema coercer,然后试图强制我得到了一组数据:
#schema.utils.ErrorContainer{:error #<ValidationError schema.utils.ValidationError@2abfe6ca>}
如何获得实际验证错误的解释?
最佳答案
您可以找到 ValidationError
类型 here 的定义(因为您似乎在 JVM 上使用了 Clojure,所以我删除了 #+cljs
表达式):
(deftype ValidationError [schema value expectation-delay fail-explanation])
ErrorContainer
记录 here 的定义:(defrecord ErrorContainer [error])
因此,要获取有关错误的更多信息,您可以访问内部
ValidationError
的任何字段:(defn validation-error-details [error]
(let [values (juxt #(.schema %)
#(.value %)
#(.expectation-delay %)
#(.fail-explanation %))]
(->> error :error values)))
;; Usage
(validation-error-details error) ; where error holds the value you posted
关于clojure - 如何检查在棱镜模式强制期间引发的 ValidationError?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28529535/