diff --git a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go index 683b9c3d8eab..fbabe92a3772 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go +++ b/src/go/rpk/pkg/cli/cmd/topic/add_partitions.go @@ -11,6 +11,8 @@ package topic import ( "context" + "errors" + "fmt" "os" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" @@ -18,6 +20,7 @@ import ( "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 { @@ -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) diff --git a/src/go/rpk/pkg/cli/cmd/topic/create.go b/src/go/rpk/pkg/cli/cmd/topic/create.go index ec42df37daaf..218e9dc261a8 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/create.go +++ b/src/go/rpk/pkg/cli/cmd/topic/create.go @@ -11,6 +11,8 @@ package topic import ( "context" + "errors" + "fmt" "os" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" @@ -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)