Skip to content

Commit

Permalink
Log error when multiple existing palaute is found
Browse files Browse the repository at this point in the history
Log error instead of raising assertion error
  • Loading branch information
severij committed Jan 8, 2025
1 parent 07a6f19 commit 210147d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/oph/ehoks/palaute/opiskelija.clj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@
(log/spyf :info "existing-heratteet!: before rk filtering: %s")
(filterv #(= rahoituskausi (palaute/rahoituskausi (:heratepvm %))))
(log/spyf :info "existing-heratteet!: after rk filtering: %s")
(utils/assert-pred #(contains? #{0 1} (count %)))
((fn [existing-palautteet]
(when (> (count existing-palautteet) 1)
(log/errorf (str "Found more than one existing herate for "
"`%s` of HOKS `%d` in rahoituskausi `%s`.")
kysely-type
(:id hoks)
rahoituskausi))
existing-palautteet))
first)))

(defn build!
Expand Down
12 changes: 1 addition & 11 deletions src/oph/ehoks/utils.clj
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
(ns oph.ehoks.utils
(:require [clojure.string :as string]
[medley.core :refer [dissoc-in map-keys]])
(:import (java.text Normalizer Normalizer$Form)))
(:require [medley.core :refer [dissoc-in map-keys]]))

(defn apply-when
"Apply function `f` to value `v` if predicate `(pred v)` returns `true`.
Otherwise returns value `v` unchanged. Useful when used in a threading macro."
[v pred f]
(if (pred v) (f v) v))

(defn assert-pred
"Takes a predicate `pred` and a value `v` that is given to the predicate.
Asserts that `(pred v)` returns `true` and then returns `v`. Useful when used
in a threading macro."
[pred v]
(assert (pred v))
v)

(defn to-underscore-str
[kw]
(.replace (name kw) \- \_))
Expand Down

0 comments on commit 210147d

Please sign in to comment.