Handle all bank loading gracefully.

This commit is contained in:
Dominik Pantůček 2023-04-04 22:34:41 +02:00
parent cc4cfccae1
commit e25a75ab27
5 changed files with 51 additions and 29 deletions

View file

@ -42,6 +42,7 @@
(chicken sort)
(chicken process-context)
(chicken pathname)
(chicken condition)
bank-account
member-record
members-base
@ -49,7 +50,8 @@
dictionary
member-fees
period
configuration)
configuration
utils)
;; Exchange rates
(define exchange-rates-lookup-table
@ -103,9 +105,15 @@
;; Reads the payments
(define (load-accounts-list apikeys)
(map (compose car string-split)
(read-lines
(open-input-file apikeys))))
(call/cc
(lambda (ret)
(with-exception-handler
(lambda (ex)
(ret #f))
(lambda ()
(map (compose car string-split)
(read-lines
(open-input-file apikeys))))))))
;; Loads all accounts - it expects .csv files in given directory.
(define (load-accounts accounts-list dir)
@ -117,13 +125,17 @@
;; accounts and processes transactions.
(define (members-payments-process mb apikeys-file dir)
(if apikeys-file
(let* ((accounts (load-accounts
(load-accounts-list apikeys-file)
dir)))
(map member-sort-payments
(foldl members-payments-process-bank
mb
accounts)))
(let* ((acc-list (load-accounts-list apikeys-file))
(accounts (if acc-list (load-accounts acc-list dir) #f)))
(if accounts
(map member-sort-payments
(foldl members-payments-process-bank
mb
(filter identity
accounts)))
(let ()
(print "Warning: no accounts loaded!")
mb)))
mb))
;; Adds all balances - payments are converted to CZK in member-payments-total