favor %w over %s for error wrapping

This commit is contained in:
vilmibm 2020-04-20 12:22:12 -05:00
parent e823ad0c6c
commit bd907ec74d
3 changed files with 7 additions and 7 deletions

View file

@ -99,12 +99,12 @@ func configSet(cmd *cobra.Command, args []string) error {
err = cfg.Set(hostname, key, value)
if err != nil {
return fmt.Errorf("failed to set %q to %q: %s", key, value, err)
return fmt.Errorf("failed to set %q to %q: %w", key, value, err)
}
err = cfg.Write()
if err != nil {
return fmt.Errorf("failed to write config to disk: %s", err)
return fmt.Errorf("failed to write config to disk: %w", err)
}
return nil

View file

@ -142,7 +142,7 @@ func migrateConfig(fn string, root *yaml.Node) error {
err = BackupConfigFile(fn)
if err != nil {
return fmt.Errorf("failed to back up existing config: %s", err)
return fmt.Errorf("failed to back up existing config: %w", err)
}
return WriteConfigFile(fn, newConfig)
@ -162,7 +162,7 @@ func ParseConfig(fn string) (Config, error) {
_, root, err = parseConfigFile(fn)
if err != nil {
return nil, fmt.Errorf("failed to reparse migrated config: %s", err)
return nil, fmt.Errorf("failed to reparse migrated config: %w", err)
}
}

View file

@ -132,7 +132,7 @@ func (c *fileConfig) Set(hostname, key, value string) error {
func (c *fileConfig) configForHost(hostname string) (*HostConfig, error) {
hosts, err := c.Hosts()
if err != nil {
return nil, fmt.Errorf("failed to parse hosts config: %s", err)
return nil, fmt.Errorf("failed to parse hosts config: %w", err)
}
for _, hc := range hosts {
@ -159,12 +159,12 @@ func (c *fileConfig) Hosts() ([]*HostConfig, error) {
_, hostsEntry, err := c.FindEntry("hosts")
if err != nil {
return nil, fmt.Errorf("could not find hosts config: %s", err)
return nil, fmt.Errorf("could not find hosts config: %w", err)
}
hostConfigs, err := c.parseHosts(hostsEntry)
if err != nil {
return nil, fmt.Errorf("could not parse hosts config: %s", err)
return nil, fmt.Errorf("could not parse hosts config: %w", err)
}
c.hosts = hostConfigs