lima-vm/lima · error

unexpected option %#q

Error message

unexpected option %#q

What it means

When formatting as an ssh_config block, each option must be a key=value string (split on the first '='). An option without '=' cannot be rendered as a config directive, so Format rejects it. This preserves the invariant that every opts entry maps to one 'Key Value' line in the config.

Source

Thrown at pkg/sshutil/format.go:97

		args = append(args, fakeHostname)
		// the args are similar to `limactl shell` but not exactly same. (e.g., lacks -t)
		fmt.Fprintln(w, strings.Join(args, " ")) // no need to use shellescape.QuoteCommand
	case FormatArgs:
		var args []string
		for _, o := range opts {
			args = append(args, "-o", quoteOption(o))
		}
		fmt.Fprintln(w, strings.Join(args, " ")) // no need to use shellescape.QuoteCommand
	case FormatOptions:
		for _, o := range opts {
			fmt.Fprintln(w, o)
		}
	case FormatConfig:
		fmt.Fprintf(w, "Host %s\n", fakeHostname)
		for _, o := range opts {
			kv := strings.SplitN(o, "=", 2)
			if len(kv) != 2 {
				return fmt.Errorf("unexpected option %#q", o)
			}
			fmt.Fprintf(w, "  %s %s\n", kv[0], kv[1])
		}
	default:
		return fmt.Errorf("unknown format: %#q", format)
	}
	return nil
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Rewrite each option as key=value, e.g. "ForwardAgent=yes" instead of "ForwardAgent yes".
  2. Check which formatter you need: FormatCmd accepts plain option strings, FormatConfig requires key=value.
  3. Trim whitespace and inspect the offending option printed in the error for a missing '='.

Example fix

// before
opts := []string{"ForwardAgent yes", "StrictHostKeyChecking no"}
sshutil.Format(w, sshPath, instName, sshutil.FormatConfig, opts)
// after
opts := []string{"ForwardAgent=yes", "StrictHostKeyChecking=no"}
sshutil.Format(w, sshPath, instName, sshutil.FormatConfig, opts)
Defensive patterns

Strategy: validation

Validate before calling

for _, o := range opts {
    if !strings.Contains(o, "=") {
        return fmt.Errorf("option %q must be key=value for FormatConfig", o)
    }
}

Type guard

func isKVOption(o string) bool { return strings.Contains(o, "=") }

Try / catch

if err := sshutil.Format(w, sshPath, instName, sshutil.FormatConfig, opts); err != nil {
    if strings.Contains(err.Error(), "unexpected option") {
        // convert opts to key=value form and retry
    }
}

Prevention

When it happens

Trigger: Calling sshutil.Format with format=FormatConfig and an opts element lacking '=', e.g. "ForwardAgent yes" (space-separated) or a bare flag like "-v" instead of "ForwardAgent=yes".

Common situations: Hand-building the opts slice with CLI-style syntax instead of key=value pairs; copying options that were meant for FormatCmd into a FormatConfig call; typos such as missing '='.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/1b56af7eb960939c. Report an issue: GitHub.