gpt4 book ai didi

clojure - 如何检查棱柱模式强制期间引发的 ValidationError ?

转载 作者:行者123 更新时间:2023-12-02 10:41:06 28 4
gpt4 key购买 nike

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

#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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com