Skip to content

Commit

Permalink
rpk: change Invalid Partitions err message in topic creation
Browse files Browse the repository at this point in the history
  • Loading branch information
r-vasquez committed May 10, 2022
1 parent 3c58486 commit e26c0b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/go/rpk/pkg/cli/cmd/topic/add_partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ package topic

import (
"context"
"errors"
"fmt"
"os"

"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka"
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/twmb/franz-go/pkg/kerr"
)

func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command {
Expand Down Expand Up @@ -56,7 +59,11 @@ func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command {
for _, resp := range resps.Sorted() {
msg := "OK"
if e := resp.Err; e != nil {
msg = e.Error()
if errors.Is(e, kerr.InvalidPartitions) && num > 0 {
msg = fmt.Sprintf("INVALID_PARTITIONS: unable to add %d partitions due to hardware constraints", num)
} else {
msg = err.Error()
}
exit1 = true
}
tw.Print(resp.Topic, msg)
Expand Down
8 changes: 7 additions & 1 deletion src/go/rpk/pkg/cli/cmd/topic/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package topic

import (
"context"
"errors"
"fmt"
"os"

"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config"
Expand Down Expand Up @@ -99,7 +101,11 @@ the cleanup.policy=compact config option set.
for _, topic := range resp.Topics {
msg := "OK"
if err := kerr.ErrorForCode(topic.ErrorCode); err != nil {
msg = err.Error()
if errors.Is(err, kerr.InvalidPartitions) && partitions > 0 {
msg = fmt.Sprintf("INVALID_PARTITIONS: unable to create topic with %d partitions due to hardware constraints", partitions)
} else {
msg = err.Error()
}
exit1 = true
}
tw.Print(topic.Topic, msg)
Expand Down

0 comments on commit e26c0b4

Please sign in to comment.