From 3202e617ae96c9ccd1872d6c5d8e81faa01107b5 Mon Sep 17 00:00:00 2001 From: Ling Jin Date: Tue, 18 May 2021 11:09:08 +0800 Subject: [PATCH] cluster: make port check error message more clear to users. (#1367) --- pkg/cluster/spec/validate.go | 2 +- pkg/cluster/spec/validate_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cluster/spec/validate.go b/pkg/cluster/spec/validate.go index 3bdd7bfd15..d08944807c 100644 --- a/pkg/cluster/spec/validate.go +++ b/pkg/cluster/spec/validate.go @@ -532,7 +532,7 @@ func (s *Specification) portInvalidDetect() error { port := int(compSpec.Field(i).Int()) if port <= 0 || port >= 65535 { portField := strings.Split(compSpec.Type().Field(i).Tag.Get("yaml"), ",")[0] - return errors.Errorf("`%s` of %s=%d is invalid", cfg, portField, port) + return errors.Errorf("`%s` of %s=%d is invalid, port should be in the range [0, 65535]", cfg, portField, port) } } } diff --git a/pkg/cluster/spec/validate_test.go b/pkg/cluster/spec/validate_test.go index f1b8fe1b01..67351e1178 100644 --- a/pkg/cluster/spec/validate_test.go +++ b/pkg/cluster/spec/validate_test.go @@ -929,7 +929,7 @@ global: ssh_port: 65536 `), &topo) c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, "`global` of ssh_port=65536 is invalid") + c.Assert(err.Error(), Equals, "`global` of ssh_port=65536 is invalid, port should be in the range [0, 65535]") err = yaml.Unmarshal([]byte(` global: @@ -939,14 +939,14 @@ tidb_servers: port: -1 `), &topo) c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, "`tidb_servers` of port=-1 is invalid") + c.Assert(err.Error(), Equals, "`tidb_servers` of port=-1 is invalid, port should be in the range [0, 65535]") err = yaml.Unmarshal([]byte(` monitored: node_exporter_port: 102400 `), &topo) c.Assert(err, NotNil) - c.Assert(err.Error(), Equals, "`monitored` of node_exporter_port=102400 is invalid") + c.Assert(err.Error(), Equals, "`monitored` of node_exporter_port=102400 is invalid, port should be in the range [0, 65535]") } func (s *metaSuiteTopo) TestInvalidUserGroup(c *C) {