Skip to content

Commit

Permalink
Remove superfluous intermediate error state handling
Browse files Browse the repository at this point in the history
Previously in the bean codebase...

This function was taking a flag to suppress error escalation on the
initial evaluation, likely to account for a previous bug that I'm not
bothering to dig up right now.

If that last sentence sounds like it is full of forewarning, you're
right. It is.
  • Loading branch information
neenaoffline committed Nov 23, 2023
1 parent 21ae2b5 commit 3ef4e94
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/bean/code.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [bean.grid :as grid]))

(defn reevaluate [{:keys [code-in-editor] :as sheet}]
(grid/eval-code sheet code-in-editor false))
(grid/eval-code sheet code-in-editor))

(defn set-code [sheet code]
(assoc sheet :code-in-editor code))
Expand Down
10 changes: 4 additions & 6 deletions src/bean/grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
(if error
(reduced (assoc sheet :code-error (code-errors/named-ref-error named error)))
sheet))
(dissoc sheet :code-error)
(dissoc sheet :code-error) ;; reset the error from a previous evaluation
(:bindings sheet))))

(declare eval-dep)
Expand Down Expand Up @@ -224,8 +224,8 @@

(defn eval-code
;; Suppressing errors so we let the grid evaluate before showing any errors in the code
([sheet] (eval-code sheet (:code sheet) true))
([sheet code suppress-errors]
([sheet] (eval-code sheet (:code sheet)))
([sheet code]
(let [res (let [code-ast (parser/parse-statement code)
parse-error (parser/error code-ast)]
(if (string? parse-error)
Expand All @@ -238,9 +238,7 @@
(dissoc sheet :code-error)
(rest code-ast))
(assoc :code-ast code-ast))))]
(if (true? suppress-errors)
res
(escalate-bindings-errors res)))))
(escalate-bindings-errors res))))

(defn eval-sheet
([sheet]
Expand Down
11 changes: 10 additions & 1 deletion test/bean/code_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@
(is (= (-> (grid/new-sheet [["1"]] "foo: A1+\"bar\"")
grid/eval-sheet
:code-error)
"name: foo. + only works for Integers"))))
"name: foo. + only works for Integers")))

(testing "When the code has an error in a statement, it is escalated on initial
evaluation after the grid is evaluated but is cleared in a subsequent
evaluation where the error is resolved"
(is (nil? (-> (grid/new-sheet [["1"]] "foo: A1+\"bar\"")
grid/eval-sheet
(code/set-code "foo: A1+20")
code/reevaluate
:code-error)))))
2 changes: 1 addition & 1 deletion test/bean/grid_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
(is (= {[:cell [0 1]] #{[:named "addaone"]}}
(as-> (new-sheet [["1" "2"]] "addaone:4+A1") sheet
(eval-sheet sheet)
(eval-code sheet "addaone:4+B1" false)
(eval-code sheet "addaone:4+B1")
(get-in sheet [:depgraph])))))

(testing "Depgraph is updated when a named reference's dependents change"
Expand Down

0 comments on commit 3ef4e94

Please sign in to comment.