farseer icon indicating copy to clipboard operation
farseer copied to clipboard

Poor validation handling on Windows

Open Ororororo opened this issue 1 year ago • 0 comments

Validation returns "Invalid params" on Windows system despite success spec check. Test code:

(ns bug
  (:require
   [clojure.spec.alpha :as s]
   [farseer.handler :refer [make-handler]]))

(defn rpc-test
  [_ [a b]]
  (+ a b))

(s/def :bug/a int?)

(s/def :bug/b int?)

(s/def :bug/test-in (s/tuple :bug/a :bug/b))

(def config
  {:rpc/handlers
   {:bug/test
    {:handler/function rpc-test
     :handler/spec-in :bug/test-in}}})

(def api-handler
  (make-handler config))

(api-handler {:id 1
              :method :bug/test
              :params [1 2]
              :jsonrpc "2.0"})

Return:

{:error
 {:code -32602,
  :message "Invalid params",
  :data {:explain "Success!\r\n"}}}

Expected:

{:id 1, :jsonrpc "2.0", :result 3}

Cause: Function in farseer/handler.clj

(defn explain-str [spec data]
  (let [out (s/explain-str spec data)]
    (when-not (= out "Success!\n")
      out)))

Ororororo avatar Jun 14 '23 09:06 Ororororo