github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/daemon/errors.go (about) 1 package daemon 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/docker/docker/errors" 8 "github.com/docker/docker/reference" 9 ) 10 11 func (d *Daemon) imageNotExistToErrcode(err error) error { 12 if dne, isDNE := err.(ErrImageDoesNotExist); isDNE { 13 if strings.Contains(dne.RefOrID, "@") { 14 e := fmt.Errorf("No such image: %s", dne.RefOrID) 15 return errors.NewRequestNotFoundError(e) 16 } 17 tag := reference.DefaultTag 18 ref, err := reference.ParseNamed(dne.RefOrID) 19 if err != nil { 20 e := fmt.Errorf("No such image: %s:%s", dne.RefOrID, tag) 21 return errors.NewRequestNotFoundError(e) 22 } 23 if tagged, isTagged := ref.(reference.NamedTagged); isTagged { 24 tag = tagged.Tag() 25 } 26 e := fmt.Errorf("No such image: %s:%s", ref.Name(), tag) 27 return errors.NewRequestNotFoundError(e) 28 } 29 return err 30 } 31 32 type errNotRunning struct { 33 containerID string 34 } 35 36 func (e errNotRunning) Error() string { 37 return fmt.Sprintf("Container %s is not running", e.containerID) 38 } 39 40 func (e errNotRunning) ContainerIsRunning() bool { 41 return false 42 } 43 44 func errContainerIsRestarting(containerID string) error { 45 err := fmt.Errorf("Container %s is restarting, wait until the container is running", containerID) 46 return errors.NewRequestConflictError(err) 47 } 48 49 func errExecNotFound(id string) error { 50 err := fmt.Errorf("No such exec instance '%s' found in daemon", id) 51 return errors.NewRequestNotFoundError(err) 52 } 53 54 func errExecPaused(id string) error { 55 err := fmt.Errorf("Container %s is paused, unpause the container before exec", id) 56 return errors.NewRequestConflictError(err) 57 }