diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-09 20:13:59 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-09 20:13:59 +0200 |
| commit | 0e56e63c833229ca02f2c62d4ee50cf371b6ac9a (patch) | |
| tree | 0d69271229ca15b98e55d75b3b8936675aa25fcd /pkg/rtree/index.go | |
| parent | 2f93c6ca308a15c5d3e280274bd698604276143c (diff) | |
| download | gofu-0e56e63c833229ca02f2c62d4ee50cf371b6ac9a.tar.gz | |
replace panic() by a collector for early errors
Diffstat (limited to 'pkg/rtree/index.go')
| -rw-r--r-- | pkg/rtree/index.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/rtree/index.go b/pkg/rtree/index.go index c2c0202..d0813fe 100644 --- a/pkg/rtree/index.go +++ b/pkg/rtree/index.go @@ -29,6 +29,7 @@ import ( "strings" "github.com/majewsky/gofu/pkg/cli" + "github.com/majewsky/gofu/pkg/earlyerrors" yaml "gopkg.in/yaml.v2" ) @@ -38,18 +39,21 @@ type Index struct { Repos []*Repo `yaml:"repos"` } -func indexPath() string { +var indexPath string + +func init() { homeDir := os.Getenv("HOME") if homeDir == "" { - panic(errors.New("$HOME is not set (rtree needs the HOME variable to locate its index file)")) + earlyerrors.Put("$HOME is not set (rtree needs the HOME variable to locate its index file)") + } else { + indexPath = filepath.Join(homeDir, ".rtree/index.yaml") } - return filepath.Join(homeDir, ".rtree/index.yaml") } //ReadIndex reads the index file. func ReadIndex() (*Index, []error) { //read contents of index file - path := indexPath() + path := indexPath buf, err := ioutil.ReadFile(path) if err != nil { if os.IsNotExist(err) { @@ -106,7 +110,7 @@ func (i *Index) Write(ci *cli.Interface) error { return err } - path := indexPath() + path := indexPath err = os.MkdirAll(filepath.Dir(path), 0755) if err != nil { return err |
