Skip to content

Commit 7f9d2db

Browse files
committed
Improve error message when code owner feature is unavailable
1 parent 22be0f8 commit 7f9d2db

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

gitlab/resource_gitlab_branch_protection.go

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

33
import (
4+
"fmt"
45
"log"
56

67
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -129,6 +130,12 @@ func resourceGitlabBranchProtectionUpdate(d *schema.ResourceData, meta interface
129130
}
130131

131132
if _, err := client.ProtectedBranches.RequireCodeOwnerApprovals(project, branch, options); err != nil {
133+
// The user might be running a version of GitLab that does not support this feature.
134+
// We enhance the generic 404 error with a more informative message.
135+
if errResponse, ok := err.(*gitlab.ErrorResponse); ok && errResponse.Response.StatusCode == 404 {
136+
return fmt.Errorf("feature unavailable: code owner approvals: %w", err)
137+
}
138+
132139
return err
133140
}
134141

gitlab/resource_gitlab_branch_protection_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ func TestAccGitlabBranchProtection_basic(t *testing.T) {
7676
}),
7777
),
7878
},
79-
// Attempting to update code owner approval setting on CE should fail safely
79+
// Attempting to update code owner approval setting on CE should fail safely and with an informative error message
8080
{
8181
SkipFunc: isRunningInEE,
8282
Config: testAccGitlabBranchProtectionUpdateConfigCodeOwnerTrue(rInt),
83-
ExpectError: regexp.MustCompile("404 Not Found"),
83+
ExpectError: regexp.MustCompile("feature unavailable: code owner approvals"),
8484
},
8585
// Update the Branch Protection to get back to initial settings
8686
{

0 commit comments

Comments
 (0)