Skip to content

Commit

Permalink
update library error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
konoui committed Jan 19, 2020
1 parent ba2f6b4 commit bd625d4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/konoui/go-alfred v0.0.0-20200104065011-50d164695438
github.com/mattn/go-shellwords v1.0.6
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/sahilm/fuzzy v0.1.0
github.com/spf13/cobra v0.0.5
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
Expand Down
6 changes: 4 additions & 2 deletions pkg/tldr/fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/sahilm/fuzzy"
)

Expand Down Expand Up @@ -58,9 +59,10 @@ func (c Cmds) Search(args []string) Cmds {

// LoadIndexFile load command index file
func (t *Tldr) LoadIndexFile() (*CmdsIndex, error) {
f, err := os.Open(filepath.Join(t.path, t.indexFile))
path := filepath.Join(t.path, t.indexFile)
f, err := os.Open(path)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to open index file")
}
defer f.Close()

Expand Down
14 changes: 8 additions & 6 deletions pkg/tldr/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path/filepath"
"strings"
"time"

"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -57,15 +59,15 @@ func (t *Tldr) OnInitialize() error {
initUpdate := false
if !pathExists(t.path) {
if err := os.Mkdir(t.path, 0755); err != nil {
return err
return errors.Wrap(err, "failed to create tldr dir")
}
// automatically updated if indexfile does not exist
initUpdate = true
}

if t.update || initUpdate {
if err := t.Update(); err != nil {
return err
return errors.Wrap(err, "failed to update tldr repository")
}
}

Expand All @@ -76,16 +78,16 @@ func (t *Tldr) OnInitialize() error {
func (t *Tldr) Update() error {
_, err := download(t.indexSourceURL, t.path, t.indexFile)
if err != nil {
return err
return errors.Wrap(err, "failed to download index file")
}

zipPath, err := download(t.pageSourceURL, t.path, t.zipFile)
if err != nil {
return err
return errors.Wrap(err, "failed to download tldr repository")
}

if err := unzip(zipPath, t.path); err != nil {
return err
return errors.Wrap(err, "failed to unzip tldr repository")
}

return nil
Expand All @@ -103,7 +105,7 @@ func (t *Tldr) FindPage(cmds []string) (*Page, error) {

f, err := os.Open(path)
if err != nil {
return &Page{}, err
return &Page{}, errors.Wrap(err, "failed to open page: "+f.Name())
}
defer f.Close()

Expand Down

0 comments on commit bd625d4

Please sign in to comment.