sipeed/picoclaw · error

failed to confirm overwrite: %w

Error message

failed to confirm overwrite: %w

What it means

When `picoclaw mcp add <name>` targets an existing server and --force is absent, the CLI prompts 'Overwrite? [y/N]' through confirmOverwrite(cmd.InOrStdin(), cmd.OutOrStdout(), name). This error wraps an I/O failure on those streams - not the answer itself. EOF on stdin is special-cased to a clean 'no' (error 149), but any other read/write error lands here.

Source

Thrown at cmd/picoclaw/internal/mcp/add.go:49

			}
			if err != nil {
				return err
			}

			cfg, err := loadConfig()
			if err != nil {
				return err
			}
			if cfg.Tools.MCP.Servers == nil {
				cfg.Tools.MCP.Servers = make(map[string]config.MCPServerConfig)
			}

			if _, exists := cfg.Tools.MCP.Servers[name]; exists && !opts.Force {
				var overwrite bool

				overwrite, err = confirmOverwrite(cmd.InOrStdin(), cmd.OutOrStdout(), name)
				if err != nil {
					return fmt.Errorf("failed to confirm overwrite: %w", err)
				}
				if !overwrite {
					return fmt.Errorf("aborted: MCP server %q already exists", name)
				}
			}

			server, err := buildServerConfig(target, targetArgs, opts)
			if err != nil {
				return err
			}

			cfg.Tools.MCP.Enabled = true
			cfg.Tools.MCP.Servers[name] = server

			if err := saveValidatedConfig(cfg); err != nil {
				return err
			}

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Use `--force` in scripts and CI to skip the prompt entirely
  2. Do not pipe the command's stdout into an early-exiting reader while it may prompt
  3. Run interactive adds in a real terminal; answer y, n, or Ctrl-C
  4. If it fired on bare Enter, re-run and answer 'n' explicitly to abort cleanly

Example fix

# before
picoclaw mcp add fs npx -y @mcp/fs | tee add.log
# after
picoclaw mcp add --force fs npx -y @mcp/fs | tee add.log
Defensive patterns

Strategy: validation

Validate before calling

# non-interactive context: always pass --force, never rely on the prompt
if [ ! -t 0 ] || [ ! -t 1 ]; then FORCE=--force; else FORCE=""; fi
picoclaw mcp add $FORCE "$@"

Try / catch

ok, err := confirmOverwrite(in, out, name)
if err != nil {
    if errors.Is(err, io.EOF) {
        return false // treat closed stdin as a clean no
    }
    return fmt.Errorf("failed to confirm overwrite: %w", err)
}

Prevention

When it happens

Trigger: stdout piped to a reader that exits early (e.g. `picoclaw mcp add ... | head`), stdin a broken pipe, or the terminal gone. Quirk: pressing bare Enter makes fmt.Fscanln return 'unexpected newline', which surfaces as this error instead of a clean abort.

Common situations: Non-interactive scripts or CI piping output; SSH session dropped at the prompt; stdin from /dev/null combined with redirected stdout that fails.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/8a9fab681023dfad. Report an issue: GitHub.