Skip to content

Commit

Permalink
fix: improve postals file load errors
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Jul 23, 2024
1 parent 53df81c commit 5be5e72
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/coords/postals/postals.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ var postalCodesMap = map[string]*Postal{}
func New(cfg *config.Config) (Postals, error) {
file, err := os.Open(cfg.PostalsFile)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to open postals file. %w", err)
}
defer file.Close()

buf, err := io.ReadAll(file)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to read postals file. %w", err)
}

var codes []*Postal
if err := json.Unmarshal(buf, &codes); err != nil {
return nil, err
return nil, fmt.Errorf("failed to unmarshal postals file. %w", err)
}

cs, err := coords.NewReadOnly[*Postal](codes)
cs, err := coords.NewReadOnly(codes)
if err != nil {
return nil, fmt.Errorf("failed to add postals to postals coords map: %w", err)
}
Expand Down

0 comments on commit 5be5e72

Please sign in to comment.