Skip to content

Commit

Permalink
fixed cumulative errors when parsing excel
Browse files Browse the repository at this point in the history
  • Loading branch information
DouglasFischer committed Aug 18, 2024
1 parent 844e259 commit aa8a000
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/excel/parser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package excel

import (
"errors"
"fmt"
"github.com/xuri/excelize/v2"
"io"
Expand Down Expand Up @@ -69,6 +70,8 @@ func ReadExcel(fileReader io.Reader) ([]CostCentre, []SecondaryCostCentre, []Bud
var secondaryCostCentreIDCounter = 0
var budgetLineIDCounter = 0

var omegaError error

//[1:] excludes the first sheet
for sheetIndex, sheetName := range sheets[1:] {

Expand Down Expand Up @@ -142,12 +145,14 @@ func ReadExcel(fileReader io.Reader) ([]CostCentre, []SecondaryCostCentre, []Bud

budgetLineIncome, err := sanitizeBudgetValue(budgetLineIncomeString, secondaryCostCentre)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to sanitize budget value: %v", err)
omegaError = errors.Join(omegaError, err)
//return nil, nil, nil, fmt.Errorf("failed to sanitize budget value: %v", err)
}

budgetLineExpense, err := sanitizeBudgetValue(budgetLineExpenseString, secondaryCostCentre)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to sanitize budget value: %v", err)
omegaError = errors.Join(omegaError, err)
//return nil, nil, nil, fmt.Errorf("failed to sanitize budget value: %v", err)
}

//create BudgetLine object
Expand Down Expand Up @@ -189,6 +194,9 @@ func ReadExcel(fileReader io.Reader) ([]CostCentre, []SecondaryCostCentre, []Bud
secondaryCostCentreIDCounter++
}
}
if omegaError != nil {
return nil, nil, nil, fmt.Errorf("failed to sanitize budget value(s): %w", omegaError)
}
return costCentres, secondaryCostCentres, budgetLines, nil
}

Expand Down

0 comments on commit aa8a000

Please sign in to comment.