mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
Revise err handling for CSV storage constructor
NewFileCSVStorage() now returns an error besides the storage struct itself, which is logged and returned instead of calling log.Fatal() which was causing the engine to crash. Fixed compilation errors by creating the CSVStorage separately and passing it as an argument to the TpReader constructor. Fixes #3962
This commit is contained in:
committed by
Dan Christian Bogos
parent
bd691d8301
commit
169b5500d3
@@ -172,7 +172,11 @@ func StopStartEngine(cfgPath string, waitEngine int) (*exec.Cmd, error) {
|
||||
|
||||
func LoadTariffPlanFromFolder(tpPath, timezone string, dm *DataManager, disableReverse bool,
|
||||
cacheConns, schedConns []string) error {
|
||||
loader, err := NewTpReader(dm.dataDB, NewFileCSVStorage(utils.CSVSep, tpPath), "",
|
||||
csvStorage, err := NewFileCSVStorage(utils.CSVSep, tpPath)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
loader, err := NewTpReader(dm.dataDB, csvStorage, "",
|
||||
timezone, cacheConns, schedConns, false)
|
||||
if err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -86,10 +86,10 @@ func NewCSVStorage(sep rune,
|
||||
}
|
||||
|
||||
// NewFileCSVStorage returns a csv storage that uses all files from the folder
|
||||
func NewFileCSVStorage(sep rune, dataPath string) *CSVStorage {
|
||||
func NewFileCSVStorage(sep rune, dataPath string) (*CSVStorage, error) {
|
||||
allFoldersPath, err := getAllFolders(dataPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, fmt.Errorf("could not retrieve any folders from %q: %v", dataPath, err)
|
||||
}
|
||||
resourcesPaths := appendName(allFoldersPath, utils.ResourcesCsv)
|
||||
statsPaths := appendName(allFoldersPath, utils.StatsCsv)
|
||||
@@ -120,7 +120,7 @@ func NewFileCSVStorage(sep rune, dataPath string) *CSVStorage {
|
||||
rateProfilesFn,
|
||||
actionProfilesFn,
|
||||
accountsFn,
|
||||
)
|
||||
), nil
|
||||
}
|
||||
|
||||
// NewStringCSVStorage creates a csv storage from strings
|
||||
|
||||
@@ -120,8 +120,11 @@ func testLoaderITRemoveLoad(t *testing.T) {
|
||||
t.Error("Failed validating data: ", err.Error())
|
||||
}
|
||||
}*/
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSVSep,
|
||||
path.Join(*utils.DataDir, "tariffplans", *tpCsvScenario)), "", "",
|
||||
csvStorage, err := NewFileCSVStorage(utils.CSVSep, path.Join(*utils.DataDir, "tariffplans", *tpCsvScenario))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), csvStorage, "", "",
|
||||
[]string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -169,8 +172,11 @@ func testLoaderITLoadFromCSV(t *testing.T) {
|
||||
t.Error("Failed validating data: ", err.Error())
|
||||
}
|
||||
}*/
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSVSep,
|
||||
path.Join(*utils.DataDir, "tariffplans", *tpCsvScenario)), "", "",
|
||||
csvStorage, err := NewFileCSVStorage(utils.CSVSep, path.Join(*utils.DataDir, "tariffplans", *tpCsvScenario))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loader, err = NewTpReader(dataDbCsv.DataDB(), csvStorage, "", "",
|
||||
[]string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil, false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user