Skip to content

Commit

Permalink
Revert "flatten validation errors"
Browse files Browse the repository at this point in the history
This reverts commit 6d763ca.
  • Loading branch information
aalu1418 committed May 23, 2024
1 parent 76ce2a8 commit d4bfeee
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/solana/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ func (cs TOMLConfigs) ValidateConfig() (err error) {
}

func (cs TOMLConfigs) validateKeys() (err error) {
errA := []error{}

// Unique chain IDs
chainIDs := config.UniqueStrings{}
for i, c := range cs {
if chainIDs.IsDupe(c.ChainID) {
errA = append(errA, config.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), *c.ChainID))
err = errors.Join(err, config.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), *c.ChainID))
}
}

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

func (cs *TOMLConfigs) SetFrom(fs *TOMLConfigs) (err error) {
Expand Down Expand Up @@ -181,18 +179,16 @@ func setFromChain(c, f *Chain) {
}

func (c *TOMLConfig) ValidateConfig() (err error) {
errA := []error{}

if c.ChainID == nil {
errA = append(errA, config.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
err = errors.Join(err, config.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
} else if *c.ChainID == "" {
errA = append(errA, config.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
err = errors.Join(err, config.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
}

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

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

0 comments on commit d4bfeee

Please sign in to comment.