Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
 * Remove dryStartCallback from sampleManager.
 * Unexport ErrStateEngineStopped->errStateEngineStopped.
 * Simplify multiError string when there's only one error.
 * Fix mistakenly swapped logging of dry start/ensure errors.
  • Loading branch information
anpep committed Jun 9, 2023
1 parent 8ecc565 commit 901dcd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 1 addition & 5 deletions internals/overlord/overlord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ func (ovs *overlordSuite) TestCheckpoint(c *C) {
}

type sampleManager struct {
dryStartCallback func()
ensureCallback func()
ensureCallback func()
}

func newSampleManager(s *state.State, runner *state.TaskRunner) *sampleManager {
Expand Down Expand Up @@ -560,9 +559,6 @@ func newSampleManager(s *state.State, runner *state.TaskRunner) *sampleManager {
}

func (sm *sampleManager) DryStart() error {
if sm.dryStartCallback != nil {
sm.dryStartCallback()
}
return nil
}

Expand Down
12 changes: 8 additions & 4 deletions internals/overlord/stateengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/canonical/pebble/internals/overlord/state"
)

var ErrStateEngineStopped = errors.New("state engine already stopped")
var errStateEngineStopped = errors.New("state engine already stopped")

// StateManager is implemented by types responsible for observing
// the system and manipulating it to reflect the desired state.
Expand Down Expand Up @@ -85,6 +85,10 @@ type multiError struct {
}

func (e *multiError) Error() string {
if len(e.errs) == 1 {
return e.errs[0].Error()
}

errStrings := make([]string, len(e.errs))
for i, err := range e.errs {
errStrings[i] = err.Error()
Expand All @@ -98,13 +102,12 @@ func (se *StateEngine) DryStart() error {
se.mgrLock.Lock()
defer se.mgrLock.Unlock()
if se.stopped {
return ErrStateEngineStopped
return errStateEngineStopped
}
var errs []error
for _, m := range se.managers {
err := m.DryStart()
if err != nil {
logger.Noticef("dry start error: %v", err)
errs = append(errs, err)
}
}
Expand All @@ -126,12 +129,13 @@ func (se *StateEngine) Ensure() error {
se.mgrLock.Lock()
defer se.mgrLock.Unlock()
if se.stopped {
return ErrStateEngineStopped
return errStateEngineStopped
}
var errs []error
for _, m := range se.managers {
err := m.Ensure()
if err != nil {
logger.Noticef("state ensure error: %v", err)
errs = append(errs, err)
}
}
Expand Down

0 comments on commit 901dcd4

Please sign in to comment.