Skip to content

Commit 0347c60

Browse files
authored
fix: wrap KError into error returned by IncrementalAlterConfig (#3352)
Allow use of errors.Is(...) to test against KError values when IncrementalAlterConfigs returns an error. Signed-off-by: Adrian Preston <[email protected]>
1 parent e566998 commit 0347c60

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

admin.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,12 @@ func (ca *clusterAdmin) IncrementalAlterConfig(resourceType ConfigResourceType,
826826

827827
for _, rspResource := range rsp.Resources {
828828
if rspResource.Name == name {
829-
if rspResource.ErrorMsg != "" {
830-
return errors.New(rspResource.ErrorMsg)
831-
}
832-
if rspResource.ErrorCode != 0 {
833-
return KError(rspResource.ErrorCode)
829+
if rspResource.ErrorCode != int16(ErrNoError) {
830+
err = KError(rspResource.ErrorCode)
831+
if rspResource.ErrorMsg != "" {
832+
err = fmt.Errorf("%w: %s", err, rspResource.ErrorMsg)
833+
}
834+
return err
834835
}
835836
}
836837
}

admin_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,9 @@ func TestClusterAdminIncrementalAlterConfigWithErrorCode(t *testing.T) {
10721072
if err == nil {
10731073
t.Fatal(errors.New("ErrorCode present but no Error returned"))
10741074
}
1075+
if !errors.Is(err, ErrInvalidConfig) {
1076+
t.Fatal(errors.New("ErrorCode present but not wrapped into returned error"))
1077+
}
10751078
}
10761079

10771080
func TestClusterAdminIncrementalAlterBrokerConfig(t *testing.T) {

mockresponses.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,8 @@ func (mr *MockIncrementalAlterConfigsResponseWithErrorCode) For(reqBody versione
10291029
res.Resources = append(res.Resources, &AlterConfigsResourceResponse{
10301030
Name: r.Name,
10311031
Type: r.Type,
1032-
ErrorCode: 83,
1033-
ErrorMsg: "",
1032+
ErrorCode: int16(ErrInvalidConfig),
1033+
ErrorMsg: "Invalid value xyz for configuration retention.ms: Not a number of type LONG",
10341034
})
10351035
}
10361036
return res

0 commit comments

Comments
 (0)