From 7795904f7873fbb3a59f3c0840e89daf890a682c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 19 May 2017 15:19:54 -0400 Subject: [PATCH] Check for potentially nil response from GitHub API client. --- builtin/providers/github/resource_github_issue_label.go | 4 +++- .../providers/github/resource_github_organization_webhook.go | 2 +- builtin/providers/github/resource_github_repository.go | 2 +- .../providers/github/resource_github_repository_webhook.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin/providers/github/resource_github_issue_label.go b/builtin/providers/github/resource_github_issue_label.go index 5a1f6eea4..5b92de648 100644 --- a/builtin/providers/github/resource_github_issue_label.go +++ b/builtin/providers/github/resource_github_issue_label.go @@ -84,7 +84,9 @@ func resourceGithubIssueLabelCreateOrUpdate(d *schema.ResourceData, meta interfa } else { log.Printf("[DEBUG] Creating label: %s/%s (%s: %s)", o, r, n, c) _, resp, err := client.Issues.CreateLabel(context.TODO(), o, r, label) - log.Printf("[DEBUG] Response from creating label: %s", *resp) + if resp != nil { + log.Printf("[DEBUG] Response from creating label: %s", *resp) + } if err != nil { return err } diff --git a/builtin/providers/github/resource_github_organization_webhook.go b/builtin/providers/github/resource_github_organization_webhook.go index 5eed3dd44..9acc6f164 100644 --- a/builtin/providers/github/resource_github_organization_webhook.go +++ b/builtin/providers/github/resource_github_organization_webhook.go @@ -94,7 +94,7 @@ func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interfac hook, resp, err := client.Organizations.GetHook(context.TODO(), meta.(*Organization).name, hookID) if err != nil { - if resp.StatusCode == 404 { + if resp != nil && resp.StatusCode == 404 { d.SetId("") return nil } diff --git a/builtin/providers/github/resource_github_repository.go b/builtin/providers/github/resource_github_repository.go index ca889bc4f..b97bb949e 100644 --- a/builtin/providers/github/resource_github_repository.go +++ b/builtin/providers/github/resource_github_repository.go @@ -127,7 +127,7 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] read github repository %s/%s", meta.(*Organization).name, repoName) repo, resp, err := client.Repositories.Get(context.TODO(), meta.(*Organization).name, repoName) if err != nil { - if resp.StatusCode == 404 { + if resp != nil && resp.StatusCode == 404 { log.Printf( "[WARN] removing %s/%s from state because it no longer exists in github", meta.(*Organization).name, diff --git a/builtin/providers/github/resource_github_repository_webhook.go b/builtin/providers/github/resource_github_repository_webhook.go index 503e61c95..3c77e1032 100644 --- a/builtin/providers/github/resource_github_repository_webhook.go +++ b/builtin/providers/github/resource_github_repository_webhook.go @@ -89,7 +89,7 @@ func resourceGithubRepositoryWebhookRead(d *schema.ResourceData, meta interface{ hook, resp, err := client.Repositories.GetHook(context.TODO(), meta.(*Organization).name, d.Get("repository").(string), hookID) if err != nil { - if resp.StatusCode == 404 { + if resp != nil && resp.StatusCode == 404 { d.SetId("") return nil }