Skip to content

Commit

Permalink
More informative error messages (#7)
Browse files Browse the repository at this point in the history
* More informative error messages

* Removed redundancies
  • Loading branch information
garbelini authored Oct 12, 2020
1 parent b9c51c7 commit 1bca78b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
8 changes: 7 additions & 1 deletion drone/resource_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func resourceCronRead(data *schema.ResourceData, meta interface{}) error {
}
cronName := data.Get("name").(string)
cron, err := client.Cron(owner, repo, cronName)
if err != nil {
return fmt.Errorf("failed to read Drone Cron: %s/%s/%s", owner, repo, cronName)
}

return readCron(data, cron, owner, repo, err)
}
Expand Down Expand Up @@ -138,8 +141,11 @@ func resourceCronExists(data *schema.ResourceData, meta interface{}) (bool, erro
}
cronName := data.Get("name").(string)
cron, err := client.Cron(owner, repo, cronName)
if err != nil {
return false, fmt.Errorf("failed to read Drone Cron: %s/%s/%s", owner, repo, cronName)
}

exists := (cron.Name == cronName) && (err == nil)
exists := cron.Name == cronName
return exists, err
}

Expand Down
5 changes: 2 additions & 3 deletions drone/resource_orgsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package drone

import (
"fmt"

"github.com/Lucretius/terraform-provider-drone/drone/utils"
"github.com/drone/drone-go/drone"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -74,7 +73,7 @@ func resourceOrgSecretRead(data *schema.ResourceData, meta interface{}) error {

secret, err := client.OrgSecret(namespace, name)
if err != nil {
return err
return fmt.Errorf("failed to read Drone Org Secret: %s/%s", namespace, name)
}

readOrgSecret(data, namespace, secret)
Expand Down Expand Up @@ -120,7 +119,7 @@ func resourceOrgSecretExists(data *schema.ResourceData, meta interface{}) (bool,

secret, err := client.OrgSecret(namespace, name)
if err != nil {
return false, err
return false, fmt.Errorf("failed to read Drone Org Secret: %s/%s", namespace, name)
}

exists := (secret.Name == name) && (err == nil)
Expand Down
8 changes: 7 additions & 1 deletion drone/resource_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func resourceRepoRead(data *schema.ResourceData, meta interface{}) error {
}

repository, err := client.Repo(owner, repo)
if err != nil {
return fmt.Errorf("failed to read Drone Repo: %s/%s", owner, repo)
}

return readRepo(data, repository, err)
}
Expand Down Expand Up @@ -144,8 +147,11 @@ func resourceRepoExists(data *schema.ResourceData, meta interface{}) (bool, erro
}

repository, err := client.Repo(owner, repo)
if err != nil {
return false, fmt.Errorf("failed to read Drone Repo: %s/%s", owner, repo)
}

exists := (repository.Namespace == owner) && (repository.Name == repo) && (err == nil)
exists := (repository.Namespace == owner) && (repository.Name == repo)

return exists, err
}
Expand Down
8 changes: 7 additions & 1 deletion drone/resource_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func resourceSecretRead(data *schema.ResourceData, meta interface{}) error {
}

secret, err := client.Secret(owner, repo, name)
if err != nil {
return fmt.Errorf("failed to read Drone Secret: %s/%s/%s", owner, repo, name)
}

return readSecret(data, owner, repo, secret, err)
}
Expand Down Expand Up @@ -119,8 +122,11 @@ func resourceSecretExists(data *schema.ResourceData, meta interface{}) (bool, er
}

secret, err := client.Secret(owner, repo, name)
if err != nil {
return false, fmt.Errorf("failed to read Drone Secret: %s/%s/%s", owner, repo, name)
}

exists := (secret.Name == name) && (err == nil)
exists := secret.Name == name

return exists, err
}
Expand Down
9 changes: 5 additions & 4 deletions drone/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package drone

import (
"fmt"

"github.com/Lucretius/terraform-provider-drone/drone/utils"
"github.com/drone/drone-go/drone"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -77,9 +76,8 @@ func resourceUserRead(data *schema.ResourceData, meta interface{}) error {
client := meta.(drone.Client)

user, err := client.User(data.Id())

if err != nil {
return fmt.Errorf("Unable to read user %s: %v", user.Login, err)
return fmt.Errorf("failed to read Drone user with id: %s", data.Id())
}

return readUser(data, user, err)
Expand All @@ -97,8 +95,11 @@ func resourceUserExists(data *schema.ResourceData, meta interface{}) (bool, erro
login := data.Id()

user, err := client.User(login)
if err != nil {
return false, fmt.Errorf("failed to read Drone user with id: %s", data.Id())
}

exists := (user.Login == login) && (err == nil)
exists := user.Login == login

return exists, err
}
Expand Down

0 comments on commit 1bca78b

Please sign in to comment.