Skip to content

Commit bfb0efc

Browse files
committed
Improved error messages
1 parent 5da8a13 commit bfb0efc

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.1.0
1+
v1.1.1

internal/ansible/inventory/inventory.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package inventory
22

33
import (
4-
"errors"
54
"fmt"
65
"github.com/habakke/terraform-ansible-provider/internal/ansible/database"
76
"io/ioutil"
@@ -69,7 +68,7 @@ func (s *Inventory) GetAndLoadDatabase() (*database.Database, error) {
6968
// Load loads the inventory from disk
7069
func (s *Inventory) Load() (string, error) {
7170
if _, err := os.Stat(s.groupVarsFile); os.IsNotExist(err) {
72-
return "", errors.New("failed to load inventory because groupvars files doesn't exist")
71+
return "", fmt.Errorf("failed to load inventory because groupvars files doesn't exist: %s", err.Error())
7372
}
7473

7574
if data, err := ioutil.ReadFile(s.groupVarsFile); err != nil {
@@ -82,11 +81,11 @@ func (s *Inventory) Load() (string, error) {
8281
// Commit saves groupVars for the inventory to disk
8382
func (s *Inventory) Commit(groupVars string) error {
8483
if err := os.MkdirAll(fmt.Sprintf("%s%sgroup_vars", s.fullPath, string(os.PathSeparator)), os.ModePerm); err != nil {
85-
return errors.New("failed to create inventory path")
84+
return fmt.Errorf("failed to create inventory path: %s", err.Error())
8685
}
8786

8887
if err := ioutil.WriteFile(s.groupVarsFile, []byte(groupVars), os.ModePerm); err != nil {
89-
return errors.New("failed to commit inventory to file")
88+
return fmt.Errorf("failed to commit inventory to file: %s", err.Error())
9089
}
9190

9291
return nil

internal/ansible/resource_ansible_inventory.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func ansibleInventoryResourceQueryCreate(ctx context.Context, d *schema.Resource
4444
i := inventory.NewInventory(conf.Path)
4545
log.Debug().Str("id", i.GetID()).Msg("created new inventory")
4646
if err := i.Commit(groupVars); err != nil {
47-
log.Error().Err(err).Msg("failed to commit inventory")
4847
return diag.Errorf("failed to commit inventory: %s", err.Error())
4948
}
5049
conf.Mutex.Unlock()

0 commit comments

Comments
 (0)