【问题标题】:How to inspect ValidationError raised during Prismatic Schema coercion?如何检查 Prismatic Sc​​hema 强制期间引发的 ValidationError?
【发布时间】:2015-04-16 06:17:16
【问题描述】:

由于创建了 Schema 强制器,然后尝试强制执行一组数据,我得到的结果是:

#schema.utils.ErrorContainer{:error #<ValidationError schema.utils.ValidationError@2abfe6ca>}

如何了解实际的验证错误是什么?

【问题讨论】:

  • 您可以在某处发布一个最小的代码示例以便其他人可以查看吗?

标签: clojure plumatic-schema


【解决方案1】:

您可以找到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

【讨论】:

    猜你喜欢
    • 2014-08-14
    • 2016-09-28
    • 2016-09-17
    • 2016-07-16
    • 2017-09-29
    • 2017-09-26
    • 1970-01-01
    • 2015-11-14
    • 2019-01-14
    相关资源
    最近更新 更多