Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: use errors.join #721

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{} // goal: remove and go back to only errors.Join (https://smartcontract-it.atlassian.net/browse/BCI-3330)

// 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
Loading