Skip to content

Commit

Permalink
adding nil checks to configset juggling
Browse files Browse the repository at this point in the history
  • Loading branch information
kasey committed Jan 18, 2024
1 parent 358264e commit 71389c1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion config/params/configset.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func (r *configset) replace(cfg *BeaconChainConfig) error {

func (r *configset) replaceWithUndo(cfg *BeaconChainConfig) (func() error, error) {
name := cfg.ConfigName
prev := r.nameToConfig[name].Copy()
prev := r.nameToConfig[name]
if prev != nil {
prev = prev.Copy()
}
if err := r.replace(cfg); err != nil {
return nil, err
}
Expand Down Expand Up @@ -142,6 +145,10 @@ func (r *configset) setActive(c *BeaconChainConfig) error {
}

func (r *configset) setActiveWithUndo(c *BeaconChainConfig) (func() error, error) {
if r.active == nil {
return nil, errors.Wrap(errCannotNullifyActive,
"active config is currently nil, refusing to construct undo method that will leave it nil again")
}
active := r.active.Copy()
r.active = c
undo, err := r.replaceWithUndo(c)
Expand Down

0 comments on commit 71389c1

Please sign in to comment.