From 9acb59389c9819fc4c4ad8976d7f023c81e87cdb Mon Sep 17 00:00:00 2001 From: AmirHossein HajiMohammadi Date: Thu, 16 Jul 2026 23:06:54 +0330 Subject: [PATCH] container rm: suppress forced not found errors Signed-off-by: AmirHossein HajiMohammadi --- cli/command/container/rm.go | 1 - cli/command/container/rm_test.go | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/command/container/rm.go b/cli/command/container/rm.go index c38256a468b4..eaa23dec04bc 100644 --- a/cli/command/container/rm.go +++ b/cli/command/container/rm.go @@ -88,7 +88,6 @@ func runRm(ctx context.Context, dockerCLI command.Cli, opts *rmOptions) error { for _, name := range opts.containers { if err := <-errChan; err != nil { if opts.force && errdefs.IsNotFound(err) { - _, _ = fmt.Fprintln(dockerCLI.Err(), err) continue } errs = append(errs, err) diff --git a/cli/command/container/rm_test.go b/cli/command/container/rm_test.go index 86f6c4e0a2e9..52452f949553 100644 --- a/cli/command/container/rm_test.go +++ b/cli/command/container/rm_test.go @@ -15,9 +15,10 @@ import ( func TestRemoveForce(t *testing.T) { for _, tc := range []struct { - name string - args []string - expectedErr string + name string + args []string + expectedErr string + expectedStderr string }{ {name: "without force", args: []string{"nosuchcontainer", "mycontainer"}, expectedErr: "no such container"}, {name: "with force", args: []string{"--force", "nosuchcontainer", "mycontainer"}, expectedErr: ""}, @@ -52,6 +53,7 @@ func TestRemoveForce(t *testing.T) { } else { assert.NilError(t, err) } + assert.Equal(t, cli.ErrBuffer().String(), tc.expectedStderr) sort.Strings(removed) assert.DeepEqual(t, removed, []string{"mycontainer", "nosuchcontainer"}) })