Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6089eaa

Browse files
zhuliquanzhuliquan
zhuliquan
authored andcommittedJul 26, 2023
feature: return KError instead of errors in AlterConfigs and DescribeConfigs
Signed-off-by: zhuliquan <[email protected]>
1 parent ecf43f4 commit 6089eaa

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed
 

‎admin.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,8 @@ func (ca *clusterAdmin) DescribeConfig(resource ConfigResource) ([]ConfigEntry,
684684

685685
for _, rspResource := range rsp.Resources {
686686
if rspResource.Name == resource.Name {
687-
if rspResource.ErrorMsg != "" {
688-
return nil, errors.New(rspResource.ErrorMsg)
689-
}
690687
if rspResource.ErrorCode != 0 {
691-
return nil, KError(rspResource.ErrorCode)
688+
return nil, &DescribeConfigError{Err: KError(rspResource.ErrorCode), ErrMsg: rspResource.ErrorMsg}
692689
}
693690
for _, cfgEntry := range rspResource.Configs {
694691
entries = append(entries, *cfgEntry)
@@ -739,11 +736,8 @@ func (ca *clusterAdmin) AlterConfig(resourceType ConfigResourceType, name string
739736

740737
for _, rspResource := range rsp.Resources {
741738
if rspResource.Name == name {
742-
if rspResource.ErrorMsg != "" {
743-
return errors.New(rspResource.ErrorMsg)
744-
}
745739
if rspResource.ErrorCode != 0 {
746-
return KError(rspResource.ErrorCode)
740+
return &AlterConfigError{Err: KError(rspResource.ErrorCode), ErrMsg: rspResource.ErrorMsg}
747741
}
748742
}
749743
}

‎alter_configs_response.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
package sarama
22

3-
import "time"
3+
import (
4+
"fmt"
5+
"time"
6+
)
47

58
// AlterConfigsResponse is a response type for alter config
69
type AlterConfigsResponse struct {
710
ThrottleTime time.Duration
811
Resources []*AlterConfigsResourceResponse
912
}
1013

14+
type AlterConfigError struct {
15+
Err KError
16+
ErrMsg string
17+
}
18+
19+
func (c *AlterConfigError) Error() string {
20+
text := c.Err.Error()
21+
if c.ErrMsg != "" {
22+
text = fmt.Sprintf("%s - %s", text, c.ErrMsg)
23+
}
24+
return text
25+
}
26+
1127
// AlterConfigsResourceResponse is a response type for alter config resource
1228
type AlterConfigsResourceResponse struct {
1329
ErrorCode int16

‎describe_configs_response.go

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ const (
3434
SourceDefault
3535
)
3636

37+
type DescribeConfigError struct {
38+
Err KError
39+
ErrMsg string
40+
}
41+
42+
func (c *DescribeConfigError) Error() string {
43+
text := c.Err.Error()
44+
if c.ErrMsg != "" {
45+
text = fmt.Sprintf("%s - %s", text, c.ErrMsg)
46+
}
47+
return text
48+
}
49+
3750
type DescribeConfigsResponse struct {
3851
Version int16
3952
ThrottleTime time.Duration

0 commit comments

Comments
 (0)
Please sign in to comment.