differ icon indicating copy to clipboard operation
differ copied to clipboard

Cannot apply patch replacing a vector with a string

Open jeremyrsellars opened this issue 2 years ago • 1 comments

When applying a patch that replaces a vector with a string, an exception can occur.

(require '[differ.core :as differ])
(let [old-state {:vec-or-string [{:num 0}]}
      new-state {:vec-or-string "a-string"}
      diff (differ/diff old-state new-state)]
  (prn diff)
  (differ/patch old-state diff))
[{:vec-or-string "a-string"} {:vec-or-string [{:num 0}]}]
; Execution error (ClassCastException) at differ.patch/vec-removals (patch.cljc:76).
; class clojure.lang.PersistentArrayMap cannot be cast to class java.lang.Number 

Thanks for differ!

jeremyrsellars avatar Nov 01 '23 03:11 jeremyrsellars

FYI, I used clojure test.check to see how well things round-tripped (by applying the diff with patch). It found a number of issues. I have fixed many of them in my fork. However, backwards-compatibility wasn't really on my mind.

My company has been saving the differ.core/diff results for a many months and using it to sync state between a CLJS client and CLJ server, but sometimes it fails. This lead me to investigate, raise this issue, and work on some changes. As of tonight, I'm unsure whether this will be a permanent fork or if it will be a PR back to your repository. I welcome any insight you may have into this. Either way, I'll keep this public for a while in case you find it useful.

jeremyrsellars avatar Nov 02 '23 01:11 jeremyrsellars