Skip to content

Commit e0d3d48

Browse files
Misc. fixes in response to code review feedback
1 parent 7e5a296 commit e0d3d48

12 files changed

+57
-67
lines changed

alterpartitionreassignments.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ type AlterPartitionReassignmentsRequestAssignment struct {
3535

3636
// AlterPartitionReassignmentsResponse is a response from the AlterPartitionReassignments API.
3737
type AlterPartitionReassignmentsResponse struct {
38-
// ErrorCode is set to a non-zero value if a top-level error was encountered.
39-
ErrorCode int
40-
41-
// ErrorMessage describes the top-level error that occured.
42-
ErrorMessage string
38+
// Error is set to a non-nil value including the code and message if a top-level
39+
// error was encountered when doing the update.
40+
Error error
4341

4442
// PartitionResults contains the specific results for each partition.
4543
PartitionResults []AlterPartitionReassignmentsResponsePartitionResult
@@ -51,11 +49,9 @@ type AlterPartitionReassignmentsResponsePartitionResult struct {
5149
// PartitionID is the ID of the partition that was altered.
5250
PartitionID int
5351

54-
// ErrorCode is set to a non-zero value if an error was encountered during the update.
55-
ErrorCode int
56-
57-
// ErrorMessage describes the partition-specific error that occurred.
58-
ErrorMessage string
52+
// Error is set to a non-nil value including the code and message if an error was encountered
53+
// during the update for this partition.
54+
Error error
5955
}
6056

6157
func (c *Client) AlterPartitionReassignments(
@@ -100,18 +96,16 @@ func (c *Client) AlterPartitionReassignments(
10096
apiResp := protoResp.(*alterpartitionreassignments.Response)
10197

10298
resp := &AlterPartitionReassignmentsResponse{
103-
ErrorCode: int(apiResp.ErrorCode),
104-
ErrorMessage: apiResp.ErrorMessage,
99+
Error: makeError(apiResp.ErrorCode, apiResp.ErrorMessage),
105100
}
106101

107102
for _, topicResult := range apiResp.Results {
108103
for _, partitionResult := range topicResult.Partitions {
109104
resp.PartitionResults = append(
110105
resp.PartitionResults,
111106
AlterPartitionReassignmentsResponsePartitionResult{
112-
PartitionID: int(partitionResult.PartitionIndex),
113-
ErrorCode: int(partitionResult.ErrorCode),
114-
ErrorMessage: partitionResult.ErrorMessage,
107+
PartitionID: int(partitionResult.PartitionIndex),
108+
Error: makeError(partitionResult.ErrorCode, partitionResult.ErrorMessage),
115109
},
116110
)
117111
}

alterpartitionreassignments_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ func TestClientAlterPartitionReassignments(t *testing.T) {
4141
if err != nil {
4242
t.Fatal(err)
4343
}
44-
if resp.ErrorCode != 0 {
45-
t.Error(
46-
"Bad error code in response",
47-
"expected", 0,
48-
"got", resp.ErrorCode,
49-
)
50-
}
5144
if len(resp.PartitionResults) != 2 {
5245
t.Error(
5346
"Unexpected length of partition results",

apiversions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ type ApiVersionsRequest struct {
1616

1717
// ApiVersionsResponse is a response from the ApiVersions API.
1818
type ApiVersionsResponse struct {
19-
// ErrorCode is set to a non-zero value if an error was encountered.
20-
ErrorCode int
19+
// Error is set to a non-nil value if an error was encountered.
20+
Error error
2121

2222
// ApiKeys contains the specific details of each supported API.
2323
ApiKeys []ApiVersionsResponseApiKey
@@ -54,7 +54,7 @@ func (c *Client) ApiVersions(
5454
apiResp := protoResp.(*apiversions.Response)
5555

5656
resp := &ApiVersionsResponse{
57-
ErrorCode: int(apiResp.ErrorCode),
57+
Error: makeError(apiResp.ErrorCode, ""),
5858
}
5959
for _, apiKey := range apiResp.ApiKeys {
6060
resp.ApiKeys = append(

apiversions_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ func TestClientApiVersions(t *testing.T) {
1616
t.Fatal(err)
1717
}
1818

19-
if resp.ErrorCode != 0 {
20-
t.Error(
21-
"Unexpected error code",
22-
"expected", 0,
23-
"got", resp.ErrorCode,
24-
)
25-
}
26-
2719
if len(resp.ApiKeys) == 0 {
2820
t.Error(
2921
"Unexpected apiKeys length",

describegroups.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ type DescribeGroupsResponse struct {
2727

2828
// DescribeGroupsResponseGroup contains the response details for a single group.
2929
type DescribeGroupsResponseGroup struct {
30+
// Error is set to a non-nil value if there was an error fetching the details
31+
// for this group.
32+
Error error
33+
3034
// GroupID is the ID of the group.
3135
GroupID string
3236

@@ -110,6 +114,7 @@ func (c *Client) DescribeGroups(
110114

111115
for _, apiGroup := range apiResp.Groups {
112116
group := DescribeGroupsResponseGroup{
117+
Error: makeError(apiGroup.ErrorCode, ""),
113118
GroupID: apiGroup.GroupID,
114119
GroupState: apiGroup.GroupState,
115120
Members: []DescribeGroupsResponseMember{},

describegroups_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ func TestClientDescribeGroups(t *testing.T) {
119119
)
120120
}
121121
g := resp.Groups[0]
122+
if g.Error != nil {
123+
t.Fatal(
124+
"Wrong error in group response",
125+
"expected", nil,
126+
"got", g.Error,
127+
)
128+
}
122129

123130
if g.GroupID != gid {
124131
t.Error(

electleaders.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type ElectLeadersRequest struct {
2525

2626
// ElectLeadersResponse is a response from the ElectLeaders API.
2727
type ElectLeadersResponse struct {
28-
// ErrorCode is set to a non-zero value if a top-level error occurred.
29-
ErrorCode int
28+
// ErrorCode is set to a non-nil value if a top-level error occurred.
29+
Error error
3030

3131
// PartitionResults contains the results for each partition leader election.
3232
PartitionResults []ElectLeadersResponsePartitionResult
@@ -37,11 +37,9 @@ type ElectLeadersResponsePartitionResult struct {
3737
// Partition is the ID of the partition.
3838
Partition int
3939

40-
// ErrorCode is set to a non-zero value if an error happened for this partition's election.
41-
ErrorCode int
42-
43-
// ErrorMessage describes the partition-specific election error that occurred.
44-
ErrorMessage string
40+
// Error is set to a non-nil value if an error occurred electing leaders
41+
// for this partition.
42+
Error error
4543
}
4644

4745
func (c *Client) ElectLeaders(
@@ -72,17 +70,16 @@ func (c *Client) ElectLeaders(
7270
apiResp := protoResp.(*electleaders.Response)
7371

7472
resp := &ElectLeadersResponse{
75-
ErrorCode: int(apiResp.ErrorCode),
73+
Error: makeError(apiResp.ErrorCode, ""),
7674
}
7775

7876
for _, topicResult := range apiResp.ReplicaElectionResults {
7977
for _, partitionResult := range topicResult.PartitionResults {
8078
resp.PartitionResults = append(
8179
resp.PartitionResults,
8280
ElectLeadersResponsePartitionResult{
83-
Partition: int(partitionResult.PartitionID),
84-
ErrorCode: int(partitionResult.ErrorCode),
85-
ErrorMessage: partitionResult.ErrorMessage,
81+
Partition: int(partitionResult.PartitionID),
82+
Error: makeError(partitionResult.ErrorCode, partitionResult.ErrorMessage),
8683
},
8784
)
8885
}

electleaders_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ func TestClientElectLeaders(t *testing.T) {
3232
if err != nil {
3333
t.Fatal(err)
3434
}
35-
if resp.ErrorCode != 0 {
36-
t.Error(
37-
"Bad error code in response",
38-
"expected", 0,
39-
"got", resp.ErrorCode,
40-
)
41-
}
4235
if len(resp.PartitionResults) != 2 {
4336
t.Error(
4437
"Unexpected length of partition results",

incrementalalterconfigs.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ type IncrementalAlterConfigsResponse struct {
6464
// IncrementalAlterConfigsResponseResource contains the response details for a single resource
6565
// whose configs were updated.
6666
type IncrementalAlterConfigsResponseResource struct {
67-
// ErrorCode is set to a non-zero value if there was an error updating the configs for this
68-
// resource.
69-
ErrorCode int
70-
71-
// ErrorMessage describes any errors that were encountered.
72-
ErrorMessage string
67+
// Error is set to a non-nil value if an error occurred while updating this specific
68+
// config.
69+
Error error
7370

7471
// ResourceType is the type of resource that was updated.
7572
ResourceType ResourceType
@@ -125,8 +122,7 @@ func (c *Client) IncrementalAlterConfigs(
125122
resp.Resources = append(
126123
resp.Resources,
127124
IncrementalAlterConfigsResponseResource{
128-
ErrorCode: int(res.ErrorCode),
129-
ErrorMessage: res.ErrorMessage,
125+
Error: makeError(res.ErrorCode, res.ErrorMessage),
130126
ResourceType: ResourceType(res.ResourceType),
131127
ResourceName: res.ResourceName,
132128
},

listgroups.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ type ListGroupsRequest struct {
1616

1717
// ListGroupsResponse is a response from the ListGroups API.
1818
type ListGroupsResponse struct {
19+
// Error is set to a non-nil value if a top-level error occurred while fetching
20+
// groups.
21+
Error error
22+
1923
// Groups contains the list of groups.
2024
Groups []ListGroupsResponseGroup
2125
}
@@ -38,7 +42,9 @@ func (c *Client) ListGroups(
3842
return nil, err
3943
}
4044
apiResp := protoResp.(*listgroups.Response)
41-
resp := &ListGroupsResponse{}
45+
resp := &ListGroupsResponse{
46+
Error: makeError(apiResp.ErrorCode, ""),
47+
}
4248

4349
for _, apiGroupInfo := range apiResp.Groups {
4450
resp.Groups = append(resp.Groups, ListGroupsResponseGroup{

listgroups_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ func TestClientListGroups(t *testing.T) {
8787
if err != nil {
8888
t.Fatal(err)
8989
}
90+
if resp.Error != nil {
91+
t.Fatal(
92+
"Unexpected error in response",
93+
"expected", nil,
94+
"got", resp.Error,
95+
)
96+
}
9097
hasGroup := false
9198
for _, group := range resp.Groups {
9299
if group.GroupID == gid {

protocol/alterpartitionreassignments/alterpartitionreassignments.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ func init() {
88

99
// Detailed API definition: https://kafka.apache.org/protocol#The_Messages_AlterPartitionReassignments
1010
type Request struct {
11-
TimeoutMs int32 `kafka:"min=v0,max=v0"`
12-
Topics []RequestTopic `kafka:"min=v0,max=v0"`
13-
1411
// We need at least one tagged field to indicate that this is a "flexible" message
1512
// type.
1613
_ struct{} `kafka:"min=v0,max=v0,tag"`
14+
15+
TimeoutMs int32 `kafka:"min=v0,max=v0"`
16+
Topics []RequestTopic `kafka:"min=v0,max=v0"`
1717
}
1818

1919
type RequestTopic struct {
@@ -35,14 +35,14 @@ func (r *Request) Broker(cluster protocol.Cluster) (protocol.Broker, error) {
3535
}
3636

3737
type Response struct {
38+
// We need at least one tagged field to indicate that this is a "flexible" message
39+
// type.
40+
_ struct{} `kafka:"min=v0,max=v0,tag"`
41+
3842
ThrottleTimeMs int32 `kafka:"min=v0,max=v0"`
3943
ErrorCode int16 `kafka:"min=v0,max=v0"`
4044
ErrorMessage string `kafka:"min=v0,max=v0,nullable"`
4145
Results []ResponseResult `kafka:"min=v0,max=v0"`
42-
43-
// We need at least one tagged field to indicate that this is a "flexible" message
44-
// type.
45-
_ struct{} `kafka:"min=v0,max=v0,tag"`
4646
}
4747

4848
type ResponseResult struct {

0 commit comments

Comments
 (0)