Improve error messages
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/pr/woodpecker Pipeline failed

This commit is contained in:
Jan Bader 2022-02-15 12:41:12 +00:00
parent 7b20bc9822
commit bb4548c50d

View File

@ -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
}