Skip to content

Commit

Permalink
Use errors.is, flatten chain
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat15 committed Sep 19, 2024
1 parent 75a4c78 commit 05907d8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions internal/storage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package storage
import (
"encoding/json"
"errors"
"io/fs"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -119,10 +120,9 @@ var _ ConfigStore = JSONConfigStore{}
// Get parses a Config from the filesystem.
func (s JSONConfigStore) Get() (Config, error) {
cfgBytes, err := os.ReadFile(filepath.Join(s.ConfigPath, configFileName))
if err != nil {
if os.IsNotExist(err) {
return Config{}, ErrConfigNotFound
}
if errors.Is(err, fs.ErrNotExist) {
return Config{}, ErrConfigNotFound
} else if err != nil {
return Config{}, err
}

Expand All @@ -149,11 +149,9 @@ func (s JSONConfigStore) Put(cfg Config) error {
}

func (s JSONConfigStore) Exists() (bool, error) {
_, err := os.Stat(filepath.Join(s.ConfigPath, configFileName))
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
if _, err := os.Stat(filepath.Join(s.ConfigPath, configFileName)); errors.Is(err, fs.ErrNotExist) {
return false, nil
} else if err != nil {
return false, err
}
return true, nil
Expand Down

0 comments on commit 05907d8

Please sign in to comment.