Skip to content

Commit 1e3ad71

Browse files
committed
Add more Table ACL error message clarity
1 parent 562a5cd commit 1e3ad71

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

access/resource_sql_permissions.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (ta *SqlPermissions) read() error {
122122
strings.Contains(failure, "RESOURCE_DOES_NOT_EXIST") {
123123
return common.NotFound(failure)
124124
}
125-
return fmt.Errorf(failure)
125+
return fmt.Errorf("cannot read current grants: %s", failure)
126126
}
127127
// clear any previous entries
128128
ta.PrivilegeAssignments = []PrivilegeAssignment{}
@@ -218,7 +218,10 @@ func (ta *SqlPermissions) apply(qb func(objType, key string) string) error {
218218
sqlQuery := qb(objType, key)
219219
log.Printf("[INFO] Executing SQL: %s", sqlQuery)
220220
r := ta.exec.Execute(ta.ClusterID, "sql", sqlQuery)
221-
return r.Err()
221+
if !r.Failed() {
222+
return nil
223+
}
224+
return fmt.Errorf("cannot execute %s: %s", sqlQuery, r.Error())
222225
}
223226

224227
func (ta *SqlPermissions) initCluster(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) (err error) {

access/resource_sql_permissions_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestTableACL_NotFound(t *testing.T) {
113113
func TestTableACL_OtherError(t *testing.T) {
114114
ta := SqlPermissions{Table: "foo", exec: failedCommand("Some error")}
115115
err := ta.read()
116-
assert.EqualError(t, err, "Some error")
116+
assert.EqualError(t, err, "cannot read current grants: Some error")
117117
}
118118

119119
func TestTableACL_Revoke(t *testing.T) {
@@ -273,7 +273,7 @@ func TestResourceSqlPermissions_Read_ErrorCommand(t *testing.T) {
273273
ID: "database/foo",
274274
Read: true,
275275
New: true,
276-
}.ExpectError(t, "does not compute")
276+
}.ExpectError(t, "cannot read current grants: does not compute")
277277
}
278278

279279
func TestResourceSqlPermissions_Create(t *testing.T) {
@@ -340,7 +340,7 @@ func TestResourceSqlPermissions_Create_Error(t *testing.T) {
340340
Fixtures: createHighConcurrencyCluster,
341341
Resource: ResourceSqlPermissions(),
342342
Create: true,
343-
}.ExpectError(t, "Some error")
343+
}.ExpectError(t, "cannot read current grants: Some error")
344344
}
345345

346346
func TestResourceSqlPermissions_Create_Error2(t *testing.T) {
@@ -366,7 +366,7 @@ func TestResourceSqlPermissions_Create_Error2(t *testing.T) {
366366
Fixtures: createHighConcurrencyCluster,
367367
Resource: ResourceSqlPermissions(),
368368
Create: true,
369-
}.ExpectError(t, "Action Unknown ActionType READ cannot be granted on tab... (127 more bytes)")
369+
}.ExpectError(t, "cannot execute GRANT READ, MODIFY, SELECT ON TABLE `default`.`foo` TO `[email protected]`: Action Unknown ActionType READ cannot be granted on tab... (127 more bytes)")
370370
}
371371

372372
func TestResourceSqlPermissions_Update(t *testing.T) {

0 commit comments

Comments
 (0)