From 3d8b49523d565867ee7a6f3e0a7c795b5aec4e79 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 19 Oct 2024 12:49:44 +0200 Subject: [PATCH] cli/command: PromptUserForCredentials: print error on terminal restore fail If restoring the terminal state fails, "echo" no longer works, which means that anything the user types is no longer shown. The login itself may already have succeeded, so we should not fail the command, but it's good to inform the user that this happened, which may give them a clue why things no longer work as they expect them to work. With this patch: docker login -u yourname Password: Error: failed to restore terminal state to echo input: something bad happened Login Succeeded We should consider printing instructions how to restore this manually (other than restarting the shell). e.g., 'run stty echo' when in a Linux or macOS shell, but PowerShell and CMD.exe may need different instructions. Signed-off-by: Sebastiaan van Stijn --- cli/command/registry.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index d5e10c191d..4699aabb0a 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -161,7 +161,15 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword if err != nil { return registrytypes.AuthConfig{}, err } - defer restoreInput() + defer func() { + if err := restoreInput(); err != nil { + // TODO(thaJeztah): we should consider printing instructions how + // to restore this manually (other than restarting the shell). + // e.g., 'run stty echo' when in a Linux or macOS shell, but + // PowerShell and CMD.exe may need different instructions. + _, _ = fmt.Fprintln(cli.Err(), "Error: failed to restore terminal state to echo input:", err) + } + }() argPassword, err = PromptForInput(ctx, cli.In(), cli.Out(), "Password: ") if err != nil {