From f9c85d4d81863ebdc879a01fe42e36a587904345 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 13 Aug 2017 12:37:09 +0200 Subject: [PATCH] Catch the error in #760 --- app/Import/Object/ImportJournal.php | 4 ++++ app/Import/Storage/ImportStorage.php | 4 +++- app/Import/Storage/ImportSupport.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Import/Object/ImportJournal.php b/app/Import/Object/ImportJournal.php index a72f574f28..48b7d7df60 100644 --- a/app/Import/Object/ImportJournal.php +++ b/app/Import/Object/ImportJournal.php @@ -85,6 +85,7 @@ class ImportJournal /** * @return string + * @throws FireflyException */ public function getAmount(): string { @@ -102,6 +103,9 @@ class ImportJournal } } } + if(bccomp($this->amount,'0') === 0) { + throw new FireflyException('Amount is zero.'); + } return $this->amount; } diff --git a/app/Import/Storage/ImportStorage.php b/app/Import/Storage/ImportStorage.php index 50980ad2a9..598380a06b 100644 --- a/app/Import/Storage/ImportStorage.php +++ b/app/Import/Storage/ImportStorage.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace FireflyIII\Import\Storage; +use ErrorException; +use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Import\Object\ImportJournal; use FireflyIII\Models\ImportJob; @@ -95,7 +97,7 @@ class ImportStorage function (ImportJournal $importJournal, int $index) { try { $this->storeImportJournal($index, $importJournal); - } catch (FireflyException $e) { + } catch (FireflyException | ErrorException | Exception $e) { $this->errors->push($e->getMessage()); Log::error(sprintf('Cannot import row #%d because: %s', $index, $e->getMessage())); } diff --git a/app/Import/Storage/ImportSupport.php b/app/Import/Storage/ImportSupport.php index 38b444b98e..aa7b1dbf99 100644 --- a/app/Import/Storage/ImportSupport.php +++ b/app/Import/Storage/ImportSupport.php @@ -214,7 +214,7 @@ trait ImportSupport */ private function getTransactionType(string $amount, Account $account): string { - $transactionType = ''; + $transactionType = TransactionType::WITHDRAWAL; // amount is negative, it's a withdrawal, opposing is an expense: if (bccomp($amount, '0') === -1) { $transactionType = TransactionType::WITHDRAWAL;