wavetermdev/waveterm · info · UserInputCancelError

canceled by the user

Error message

canceled by the user

What it means

writeToKnownHosts is called to persist a new host key into the known_hosts file after the user is asked to confirm. This error is a UserInputCancelError returned when the user explicitly declines the confirmation (response.Confirm == false). Declining is treated as a cancel of the connection rather than a generic failure, and the known_hosts file is left unmodified (file is closed without writing).

Source

Thrown at pkg/remote/sshclient.go:506

	err := os.MkdirAll(path, 0700)
	if err != nil {
		return err
	}
	f, err := os.OpenFile(knownHostsFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
	if err != nil {
		return err
	}
	// do not close writeable files with defer

	// this file works, so let's ask the user for permission
	response, err := getUserVerification()
	if err != nil {
		f.Close()
		return UserInputCancelError{Err: err}
	}
	if !response.Confirm {
		f.Close()
		return UserInputCancelError{Err: fmt.Errorf("canceled by the user")}
	}

	_, err = f.WriteString(newLine + "\n")
	if err != nil {
		f.Close()
		return err
	}
	return f.Close()
}

func createUnknownKeyVerifier(ctx context.Context, knownHostsFile string, hostname string, remote string, key ssh.PublicKey) func() (*userinput.UserInputResponse, error) {
	base64Key := base64.StdEncoding.EncodeToString(key.Marshal())
	queryText := fmt.Sprintf(
		"The authenticity of host '%s (%s)' can't be established "+
			"as it **does not exist in any checked known_hosts files**. "+
			"The host you are attempting to connect to provides this %s key:  \n"+
			"%s.\n\n"+
			"**Would you like to continue connecting?** If so, the key will be permanently "+

View on GitHub (pinned to a4447c1563)

Solutions

  1. Reconnect and accept the host-key confirmation prompt (choose Yes).
  2. Pre-populate known_hosts with the host's key (ssh-keyscan host >> known_hosts) to skip the prompt.
  3. For automation, ensure the user-input provider returns Confirm=true or pre-trust the key out of band.

Example fix

// before (manual)
$ ssh-keyscan myhost
// after
$ ssh-keyscan myhost >> ~/.ssh/known_hosts  # pre-trust so the confirm prompt isn't declined
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-trust the host key so no confirmation prompt is needed
exec.Command("ssh-keyscan", "-H", hostname).Run() // append output to known_hosts

Try / catch

err := Connect(...)
var uice UserInputCancelError
if errors.As(err, &uice) && strings.Contains(err.Error(), "canceled by the user") {
    // user declined host key trust; surface a friendly message or retry
}

Prevention

When it happens

Trigger: Connecting to a host whose key is not in any known_hosts file (unknown host verifier path) and clicking 'No' / rejecting the 'Would you like to continue connecting?' prompt.

Common situations: First-time connection to a new server where the user is unsure; automated/headless environments where the prompt times out or a UI returns Confirm=false by default; security-conscious users refusing to trust an unfamiliar key.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/acd1ddb716986924. Report an issue: GitHub.