Skip to content

Commit b7bf544

Browse files
committed
Return array of errors from contacts repository
1 parent c9164fc commit b7bf544

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/commands/list_contacts.janet

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
(print (to-csv-line contact)))
1919
plan)
2020

21+
(defn- format-command-errors [command errors]
22+
(map (fn [error] (string command " " (string/ascii-lower error) ".")) errors))
23+
2124
## —————————————————————————————————————————————————————————————————————————————————————————————————
2225
## Public Interface
2326

@@ -32,8 +35,8 @@
3235
(def argument (arguments "list-contacts"))
3336
(if argument
3437
(let [load-result (contacts_repository/load-contacts argument)
35-
error (load-result :error)]
36-
(if error
37-
{:errors [(string "--list-contacts " (string/ascii-lower error))]}
38+
errors (load-result :errors)]
39+
(if errors
40+
{:errors (format-command-errors "--list-contacts" errors)}
3841
{:command [print-contacts (load-result :contacts)]}))
3942
{}))

src/commands/schedule_contacts.janet

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
(defn- schedule-birthday-tasks [plan contacts today]
5252
(schedule-tasks plan contacts today birthday-prefix contact/birthday?))
5353

54+
(defn- format-command-errors [command errors]
55+
(map (fn [error] (string command " " (string/ascii-lower error) ".")) errors))
56+
5457
## —————————————————————————————————————————————————————————————————————————————————————————————————
5558
## Public Interface
5659

@@ -64,9 +67,9 @@
6467
(def argument (arguments "schedule-contacts"))
6568
(if argument
6669
(let [load-result (contacts_repository/load-contacts argument)
67-
error (load-result :error)
70+
errors (load-result :errors)
6871
contacts (load-result :contacts)]
69-
(if error
70-
{:errors [(string "--schedule-contacts " (string/ascii-lower error))]}
72+
(if errors
73+
{:errors (format-command-errors "--schedule-contacts" errors)}
7174
{:command [schedule-contacts contacts (date/today)]}))
7275
{}))

src/contact/repository.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
(fn [contact-file] (load-contact (string directory "/" contact-file)))
2323
(os/dir directory)))]
2424
{:contacts contacts})
25-
{:error "Directory does not exist."}))
25+
{:errors ["Directory does not exist"]}))

test/contact/repository_test.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414

1515
(deftest load-contacts-when-directory-does-not-exist
1616
(def result (load-contacts "test/missing-directory"))
17-
(is (= "Directory does not exist." (result :error))))
17+
(is (= "Directory does not exist" (first (result :errors)))))
1818

1919
(run-tests!)

0 commit comments

Comments
 (0)