Skip to content

Commit

Permalink
cmd/server: remove panic
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Aug 24, 2023
1 parent 77ab06b commit ba13bbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
12 changes: 10 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ func main() {
// Start our searcher
searcher := &searcher{logger: logger}

fedACHData := fedACHDataFile(logger)
fedWireData := fedWireDataFile(logger)
fedACHData, err := fedACHDataFile(logger)
if err != nil {
logger.LogErrorf("problem downloading FedACH: %v", err)
os.Exit(1)
}
fedWireData, err := fedWireDataFile(logger)
if err != nil {
logger.LogErrorf("problem downloading FedWire: %v", err)
os.Exit(1)
}

if err := setupSearcher(logger, searcher, fedACHData, fedWireData); err != nil {
logger.Logf("read: %v", err)
Expand Down
20 changes: 10 additions & 10 deletions cmd/server/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ import (
"github.com/moov-io/fed/pkg/download"
)

func fedACHDataFile(logger log.Logger) io.Reader {
func fedACHDataFile(logger log.Logger) (io.Reader, error) {
if file, err := attemptFileDownload(logger, "fedach"); file != nil {
return file
return file, nil
} else if err != nil {
panic(fmt.Sprintf("problem downloading fedach: %v", err))
return nil, fmt.Errorf("problem downloading fedach: %v", err)
}

path := readDataFilepath("FEDACH_DATA_PATH", "./data/FedACHdir.txt")
logger.Logf("search: loading %s for ACH data", path)

file, err := os.Open(path)
if err != nil {
panic(fmt.Sprintf("problem opening %s: %v", path, err))
return nil, fmt.Errorf("problem opening %s: %v", path, err)
}
return file
return file, nil
}

func fedWireDataFile(logger log.Logger) io.Reader {
func fedWireDataFile(logger log.Logger) (io.Reader, error) {
if file, err := attemptFileDownload(logger, "fedwire"); file != nil {
return file
return file, nil
} else if err != nil {
panic(fmt.Sprintf("problem downloading fedwire: %v", err))
return nil, fmt.Errorf("problem downloading fedwire: %v", err)
}

path := readDataFilepath("FEDWIRE_DATA_PATH", "./data/fpddir.txt")
logger.Logf("search: loading %s for Wire data", path)

file, err := os.Open(path)
if err != nil {
panic(fmt.Sprintf("problem opening %s: %v", path, err))
return nil, fmt.Errorf("problem opening %s: %v", path, err)
}
return file
return file, nil
}

func attemptFileDownload(logger log.Logger, listName string) (io.Reader, error) {
Expand Down

0 comments on commit ba13bbe

Please sign in to comment.