Skip to content

Commit e72a7b7

Browse files
authored
Merge pull request #104 from hackberrydev/file-repository-errors
Return array of errors from file repository
2 parents fa738b1 + de0b7ba commit e72a7b7

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/alas.janet

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
(import ./plan/parser :as plan_parser)
1010
(import ./plan/serializer :as plan_serializer)
1111

12+
(defn- print-errors [errors]
13+
(each error errors (print (string error "."))))
14+
1215
# Keep commands sorted alphabetically.
1316
(def argparse-params
1417
["A command line utility for planning your days"
@@ -37,9 +40,9 @@
3740

3841
(defn- run-with-file-path [arguments file-path]
3942
(def load-file-result (file_repository/load file-path))
40-
(def error (load-file-result :error))
41-
(if error
42-
(print error)
43+
(def errors (load-file-result :errors))
44+
(if errors
45+
(print-errors errors)
4346
(let [plan-string (load-file-result :text)
4447
parse-result (plan_parser/parse plan-string)
4548
parse-error (parse-result :error)

src/commands.janet

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
(import ./commands/stats)
1313

1414
(import ./date :as d)
15-
(import ./file_repository)
1615
(import ./schedule_parser)
1716

1817
# backup command needs to be first

src/commands/schedule_tasks.janet

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
(task/mark-as-missed task (day :date))))
5050
tasks))
5151

52-
(defn- format-parse-errors [errors]
52+
(defn- format-errors [errors]
5353
(map (fn [error] (string command " " (string/ascii-lower error) ".")) errors))
5454

5555
## —————————————————————————————————————————————————————————————————————————————————————————————————
@@ -72,12 +72,12 @@
7272
(def argument (arguments "schedule-tasks"))
7373
(if argument
7474
(let [load-file-result (file_repository/load argument)
75-
error (load-file-result :error)]
76-
(if error
77-
{:errors [(string command " " (string/ascii-lower error))]}
75+
errors (load-file-result :errors)]
76+
(if errors
77+
{:errors (format-errors errors)}
7878
(let [parse-result (schedule_parser/parse (load-file-result :text))
7979
errors (parse-result :errors)]
8080
(if errors
81-
{:errors (format-parse-errors errors)}
81+
{:errors (format-errors errors)}
8282
{:command [schedule-tasks (parse-result :tasks) (date/today)]}))))
8383
{}))

src/file_repository.janet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
```
2929
[path]
3030
(if (= (os/stat path) nil)
31-
{:error "File does not exist."}
31+
{:errors ["File does not exist"]}
3232
{:text (string (file/read (file/open path) :all))}))

test/file_repository_test.janet

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

4444
(deftest load-from-file-that-does-not-exist
4545
(let [result (load "missing_file.md")]
46-
(is (= "File does not exist." (result :error)))))
46+
(is (= "File does not exist" (first (result :errors))))))
4747

4848
(run-tests!)

0 commit comments

Comments
 (0)