Skip to content

Commit 964017f

Browse files
committed
Log error when multiple existing palaute is found
instead of raising assertion error
1 parent 533723d commit 964017f

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/oph/ehoks/palaute/opiskelija.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@
6868
(log/spyf :info "existing-heratteet!: before rk filtering: %s")
6969
(filterv #(= rahoituskausi (palaute/rahoituskausi (:heratepvm %))))
7070
(log/spyf :info "existing-heratteet!: after rk filtering: %s")
71-
(utils/assert-pred #(contains? #{0 1} (count %)))
71+
((fn [existing-palautteet]
72+
(when (> (count existing-palautteet) 1)
73+
(log/errorf (str "Found more than one existing herate for "
74+
"`%s` of HOKS `%d` in rahoituskausi `%s`.")
75+
kysely-type
76+
(:id hoks)
77+
rahoituskausi))
78+
existing-palautteet))
7279
first)))
7380

7481
(defn build!

src/oph/ehoks/utils.clj

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
(ns oph.ehoks.utils
2-
(:require [clojure.string :as string]
3-
[medley.core :refer [dissoc-in map-keys]])
4-
(:import (java.text Normalizer Normalizer$Form)))
2+
(:require [medley.core :refer [dissoc-in map-keys]]))
53

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

12-
(defn assert-pred
13-
"Takes a predicate `pred` and a value `v` that is given to the predicate.
14-
Asserts that `(pred v)` returns `true` and then returns `v`. Useful when used
15-
in a threading macro."
16-
[pred v]
17-
(assert (pred v))
18-
v)
19-
2010
(defn to-underscore-str
2111
[kw]
2212
(.replace (name kw) \- \_))

0 commit comments

Comments
 (0)