daemon: remove containerNotModifiedError

Removing this type, because:

- containerNotModifiedError is not an actual error, and abstracting it away
  was hiding some of these details. It also wasn't used as a sentinel error
  anywhere, so doesn't have to be its own type.
- Defining a type just to toggle the error-message between "not running"
  and "not stopped" felt a bit over-the-top, as each variant was only used once.
- So  "it only had one job", and it didn't even do that right; it produced
  capitalized error messages, which makes linters unhappy.

So, let's just inline what it does in the two places it was used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-11 21:07:19 +02:00
parent dffe634c19
commit 80d158e0de
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 7 additions and 15 deletions

View file

@ -59,19 +59,6 @@ func (e nameConflictError) Error() string {
func (nameConflictError) Conflict() {}
type containerNotModifiedError struct {
running bool
}
func (e containerNotModifiedError) Error() string {
if e.running {
return "Container is already started"
}
return "Container is already stopped"
}
func (e containerNotModifiedError) NotModified() {}
type invalidIdentifier string
func (e invalidIdentifier) Error() string {

View file

@ -30,7 +30,7 @@ func validateState(ctr *container.Container) error {
// already in the desired state. It's implemented as an error
// to make the code calling this function terminate early (as
// no further processing is needed).
return containerNotModifiedError{running: true}
return errdefs.NotModified(errors.New("container is already running"))
}
if ctr.RemovalInProgress || ctr.Dead {
return errdefs.Conflict(errors.New("container is marked for removal and cannot be started"))

View file

@ -26,7 +26,12 @@ func (daemon *Daemon) ContainerStop(ctx context.Context, name string, options co
return err
}
if !ctr.IsRunning() {
return containerNotModifiedError{}
// This is not an actual error, but produces a 304 "not modified"
// when returned through the API to indicates the container is
// already in the desired state. It's implemented as an error
// to make the code calling this function terminate early (as
// no further processing is needed).
return errdefs.NotModified(errors.New("container is already stopped"))
}
err = daemon.containerStop(ctx, ctr, options)
if err != nil {