Skip to content

Commit

Permalink
Handle errors gracefully in lastpass
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Nov 30, 2018
1 parent e612476 commit 841d2e7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/lastpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"strings"

"github.com/spf13/cobra"
vfs "github.com/twpayne/go-vfs"
"github.com/twpayne/chezmoi/lib/chezmoi"
"github.com/twpayne/go-vfs"
)

var lastpassCommand = &cobra.Command{
Expand All @@ -31,19 +32,18 @@ func (c *Config) runLastPassCommand(fs vfs.FS, cmd *cobra.Command, args []string
}

func (c *Config) lastpassFunc(id string) interface{} {
// FIXME is there a better way to return errors from template funcs?
name := c.LastPass.Lpass
args := []string{"show", "-j", id}
if c.Verbose {
fmt.Printf("%s %s\n", name, strings.Join(args, " "))
}
output, err := exec.Command(name, args...).CombinedOutput()
if err != nil {
return err
chezmoi.ReturnTemplateFuncError(fmt.Errorf("lastpass %q: %s show -j %q: %v\n%s", id, name, id, err, output))
}
var data []map[string]interface{}
if err := json.Unmarshal(output, &data); err != nil {
return err
chezmoi.ReturnTemplateFuncError(fmt.Errorf("lastpass %q: %s show -j %q: %v", id, name, id, err))
}
return data
}

0 comments on commit 841d2e7

Please sign in to comment.