Skip to content

Commit

Permalink
Fix config validation error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed May 23, 2024
1 parent 8e6d4be commit 9205525
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/cosmos/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ func (n *Node) ValidateConfig() (err error) {
type TOMLConfigs []*TOMLConfig

func (cs TOMLConfigs) validateKeys() (err error) {
var errSlice []error
// Unique chain IDs
chainIDs := config.UniqueStrings{}
for i, c := range cs {
if chainIDs.IsDupe(c.ChainID) {
err = errors.Join(err, config.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), *c.ChainID))
errSlice = append(errSlice, config.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), *c.ChainID))
}
}

Expand All @@ -164,7 +165,7 @@ func (cs TOMLConfigs) validateKeys() (err error) {
for i, c := range cs {
for j, n := range c.Nodes {
if names.IsDupe(n.Name) {
err = errors.Join(err, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
errSlice = append(errSlice, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
}
}
}
Expand All @@ -175,11 +176,12 @@ func (cs TOMLConfigs) validateKeys() (err error) {
for j, n := range c.Nodes {
u := (*url.URL)(n.TendermintURL)
if urls.IsDupeFmt(u) {
err = errors.Join(err, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.TendermintURL", i, j), u.String()))
errSlice = append(errSlice, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.TendermintURL", i, j), u.String()))
}
}
}
return

return errors.Join(errSlice...)
}

func (cs TOMLConfigs) ValidateConfig() (err error) {
Expand Down Expand Up @@ -297,17 +299,18 @@ func setFromChain(c, f *Chain) {
}

func (c *TOMLConfig) ValidateConfig() (err error) {
var errSlice []error
if c.ChainID == nil {
err = errors.Join(err, config.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
errSlice = append(errSlice, config.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
} else if *c.ChainID == "" {
err = errors.Join(err, config.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
errSlice = append(errSlice, config.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
}

if len(c.Nodes) == 0 {
err = errors.Join(err, config.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
errSlice = append(errSlice, config.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
}

return
return errors.Join(errSlice...)
}

func (c *TOMLConfig) TOMLString() (string, error) {
Expand Down

0 comments on commit 9205525

Please sign in to comment.