Improve error messages
This commit is contained in:
parent
7b20bc9822
commit
bb4548c50d
@ -67,7 +67,7 @@ func (ynab *YNABImport) ImportAssignments(r io.Reader) error {
|
|||||||
|
|
||||||
csvData, err := csv.ReadAll()
|
csvData, err := csv.ReadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read from tsv: %w", err)
|
return fmt.Errorf("read from tsv: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
@ -76,19 +76,19 @@ func (ynab *YNABImport) ImportAssignments(r io.Reader) error {
|
|||||||
dateString := record[0]
|
dateString := record[0]
|
||||||
date, err := time.Parse("Jan 2006", dateString)
|
date, err := time.Parse("Jan 2006", dateString)
|
||||||
if err != nil {
|
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 :
|
categoryGroup, categoryName := record[2], record[3] //also in 1 joined by :
|
||||||
category, err := ynab.GetCategory(categoryGroup, categoryName)
|
category, err := ynab.GetCategory(categoryGroup, categoryName)
|
||||||
if err != nil {
|
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]
|
amountString := record[4]
|
||||||
amount, err := GetAmount(amountString, "0,00€")
|
amount, err := GetAmount(amountString, "0,00€")
|
||||||
if err != nil {
|
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 {
|
if amount.Int.Int64() == 0 {
|
||||||
@ -102,7 +102,7 @@ func (ynab *YNABImport) ImportAssignments(r io.Reader) error {
|
|||||||
}
|
}
|
||||||
_, err = ynab.queries.CreateAssignment(ynab.Context, assignment)
|
_, err = ynab.queries.CreateAssignment(ynab.Context, assignment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not save assignment %v: %w", assignment, err)
|
return fmt.Errorf("save assignment %v: %w", assignment, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
@ -129,7 +129,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
|
|
||||||
csvData, err := csv.ReadAll()
|
csvData, err := csv.ReadAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read from tsv: %w", err)
|
return fmt.Errorf("read from tsv: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var openTransfers []Transfer
|
var openTransfers []Transfer
|
||||||
@ -139,7 +139,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
accountName := record[0]
|
accountName := record[0]
|
||||||
account, err := ynab.GetAccount(accountName)
|
account, err := ynab.GetAccount(accountName)
|
||||||
if err != nil {
|
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]
|
//flag := record[1]
|
||||||
@ -147,13 +147,13 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
dateString := record[2]
|
dateString := record[2]
|
||||||
date, err := time.Parse("02.01.2006", dateString)
|
date, err := time.Parse("02.01.2006", dateString)
|
||||||
if err != nil {
|
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 :
|
categoryGroup, categoryName := record[5], record[6] //also in 4 joined by :
|
||||||
category, err := ynab.GetCategory(categoryGroup, categoryName)
|
category, err := ynab.GetCategory(categoryGroup, categoryName)
|
||||||
if err != nil {
|
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]
|
memo := record[7]
|
||||||
@ -162,7 +162,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
inflow := record[9]
|
inflow := record[9]
|
||||||
amount, err := GetAmount(inflow, outflow)
|
amount, err := GetAmount(inflow, outflow)
|
||||||
if err != nil {
|
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
|
statusEnum := TransactionStatusUncleared
|
||||||
@ -190,7 +190,7 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
transferToAccountName := payeeName[11:]
|
transferToAccountName := payeeName[11:]
|
||||||
transferToAccount, err := ynab.GetAccount(transferToAccountName)
|
transferToAccount, err := ynab.GetAccount(transferToAccountName)
|
||||||
if err != nil {
|
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{
|
transfer := Transfer{
|
||||||
@ -223,11 +223,11 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
|
|
||||||
_, err = ynab.queries.CreateTransaction(ynab.Context, transfer.CreateTransactionParams)
|
_, err = ynab.queries.CreateTransaction(ynab.Context, transfer.CreateTransactionParams)
|
||||||
if err != nil {
|
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)
|
_, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams)
|
||||||
if err != nil {
|
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
|
break
|
||||||
}
|
}
|
||||||
@ -238,13 +238,13 @@ func (ynab *YNABImport) ImportTransactions(r io.Reader) error {
|
|||||||
} else {
|
} else {
|
||||||
payeeID, err := ynab.GetPayee(payeeName)
|
payeeID, err := ynab.GetPayee(payeeName)
|
||||||
if err != nil {
|
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
|
transaction.PayeeID = payeeID
|
||||||
|
|
||||||
_, err = ynab.queries.CreateTransaction(ynab.Context, transaction)
|
_, err = ynab.queries.CreateTransaction(ynab.Context, transaction)
|
||||||
if err != nil {
|
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())
|
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)
|
_, err = ynab.queries.CreateTransaction(ynab.Context, openTransfer.CreateTransactionParams)
|
||||||
if err != nil {
|
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{}
|
num := Numeric{}
|
||||||
err := num.Set(inflow)
|
err := num.Set(inflow)
|
||||||
if err != nil {
|
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
|
// if inflow is zero, use outflow
|
||||||
@ -290,7 +290,7 @@ func GetAmount(inflow string, outflow string) (Numeric, error) {
|
|||||||
|
|
||||||
err = num.Set("-" + outflow)
|
err = num.Set("-" + outflow)
|
||||||
if err != nil {
|
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
|
return num, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user