From bb4548c50d962c86e64f0c0550a31a7aa7a23883 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 15 Feb 2022 12:41:12 +0000 Subject: [PATCH] Improve error messages --- postgres/ynab-import.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/postgres/ynab-import.go b/postgres/ynab-import.go index a9b8891..6d28488 100644 --- a/postgres/ynab-import.go +++ b/postgres/ynab-import.go @@ -67,7 +67,7 @@ func (ynab *YNABImport) ImportAssignments(r io.Reader) error { csvData, err := csv.ReadAll() if err != nil { - return fmt.Errorf("could not read from tsv: %w", err) + return fmt.Errorf("read from tsv: %w", err) } count := 0 @@ -76,19 +76,19 @@ func (ynab *YNABImport) ImportAssignments(r io.Reader) error { dateString := record[0] date, err := time.Parse("Jan 2006", dateString) if err != nil { - return fmt.Errorf("could not parse date %s: %w", dateString, err) + return fmt.Errorf("parse date %s: %w", dateString, err) } categoryGroup, categoryName := record[2], record[3] //also in 1 joined by : category, err := ynab.GetCategory(categoryGroup, categoryName) if err != nil { - return fmt.Errorf("could not get category %s/%s: %w", categoryGroup, categoryName, err) + return fmt.Errorf("get category %s/%s: %w", categoryGroup, categoryName, err) } amountString := record[4] amount, err := GetAmount(amountString, "0,00€") if err != nil { - return fmt.Errorf("could not parse amount %s: %w", amountString, err) + return fmt.Errorf("parse amount %s: %w", amountString, err) } if amount.Int.Int64() == 0 { @@ -102,7 +102,7 @@ func (ynab *YNABImport) ImportAssignments(r io.Reader) error { } _, err = ynab.queries.CreateAssignment(ynab.Context, assignment) if err != nil { - return fmt.Errorf("could not save assignment %v: %w", assignment, err) + return fmt.Errorf("save assignment %v: %w", assignment, err) } count++ @@ -129,7 +129,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { csvData, err := csv.ReadAll() if err != nil { - return fmt.Errorf("could not read from tsv: %w", err) + return fmt.Errorf("read from tsv: %w", err) } var openTransfers []Transfer @@ -139,7 +139,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { accountName := record[0] account, err := ynab.GetAccount(accountName) if err != nil { - return fmt.Errorf("could not get account %s: %w", accountName, err) + return fmt.Errorf("get account %s: %w", accountName, err) } //flag := record[1] @@ -147,13 +147,13 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { dateString := record[2] date, err := time.Parse("02.01.2006", dateString) if err != nil { - return fmt.Errorf("could not parse date %s: %w", dateString, err) + return fmt.Errorf("parse date %s: %w", dateString, err) } categoryGroup, categoryName := record[5], record[6] //also in 4 joined by : category, err := ynab.GetCategory(categoryGroup, categoryName) if err != nil { - return fmt.Errorf("could not get category %s/%s: %w", categoryGroup, categoryName, err) + return fmt.Errorf("get category %s/%s: %w", categoryGroup, categoryName, err) } memo := record[7] @@ -162,7 +162,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { inflow := record[9] amount, err := GetAmount(inflow, outflow) if err != nil { - return fmt.Errorf("could not parse amount from (%s/%s): %w", inflow, outflow, err) + return fmt.Errorf("parse amount from (%s/%s): %w", inflow, outflow, err) } statusEnum := TransactionStatusUncleared @@ -190,7 +190,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { transferToAccountName := payeeName[11:] transferToAccount, err := ynab.GetAccount(transferToAccountName) if err != nil { - return fmt.Errorf("Could not get transfer account %s: %w", transferToAccountName, err) + return fmt.Errorf("get transfer account %s: %w", transferToAccountName, err) } transfer := Transfer{ @@ -223,11 +223,11 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { _, err = ynab.queries.CreateTransaction(ynab.Context, transfer.CreateTransactionParams) if err != nil { - return fmt.Errorf("could not save transaction %v: %w", transfer.CreateTransactionParams, err) + return fmt.Errorf("save transaction %v: %w", transfer.CreateTransactionParams, err) } _, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams) if err != nil { - return fmt.Errorf("could not save transaction %v: %w", openTransfer.CreateTransactionParams, err) + return fmt.Errorf("save transaction %v: %w", openTransfer.CreateTransactionParams, err) } break } @@ -238,13 +238,13 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { } else { payeeID, err := ynab.GetPayee(payeeName) if err != nil { - return fmt.Errorf("could not get payee %s: %w", payeeName, err) + return fmt.Errorf("get payee %s: %w", payeeName, err) } transaction.PayeeID = payeeID _, err = ynab.queries.CreateTransaction(ynab.Context, transaction) if err != nil { - return fmt.Errorf("could not save transaction %v: %w", transaction, err) + return fmt.Errorf("save transaction %v: %w", transaction, err) } } @@ -255,7 +255,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error { fmt.Printf("Saving unmatched transfer from %s to %s on %s over %f as regular transaction\n", openTransfer.FromAccount, openTransfer.ToAccount, openTransfer.Date, openTransfer.Amount.GetFloat64()) _, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams) if err != nil { - return fmt.Errorf("could not save transaction %v: %w", openTransfer.CreateTransactionParams, err) + return fmt.Errorf("save transaction %v: %w", openTransfer.CreateTransactionParams, err) } } @@ -280,7 +280,7 @@ func GetAmount(inflow string, outflow string) (Numeric, error) { num := Numeric{} err := num.Set(inflow) if err != nil { - return num, fmt.Errorf("Could not parse inflow %s: %w", inflow, err) + return num, fmt.Errorf("parse inflow %s: %w", inflow, err) } // if inflow is zero, use outflow @@ -290,7 +290,7 @@ func GetAmount(inflow string, outflow string) (Numeric, error) { err = num.Set("-" + outflow) if err != nil { - return num, fmt.Errorf("Could not parse outflow %s: %w", inflow, err) + return num, fmt.Errorf("parse outflow %s: %w", inflow, err) } return num, nil }