lima-vm/lima · error

unknown format: %#q

Error message

unknown format: %#q

What it means

The requested output format for formatting an SSH command/config string is not recognized (expected values like `cmd` or `args`).

Source

Thrown at pkg/sshutil/format.go:102

		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. Use the exported constants sshutil.FormatCmd or sshutil.FormatConfig instead of raw strings.
  2. Validate any externally sourced format value against the supported set before calling Format.
  3. Check for an uninitialized/zero-valued FormatT variable at the call site.

Example fix

// before
var format sshutil.FormatT
sshutil.Format(w, sshPath, instName, format, opts) // "unknown format"
// after
format := sshutil.FormatConfig
sshutil.Format(w, sshPath, instName, format, opts)
Defensive patterns

Strategy: validation

Validate before calling

if format != sshutil.FormatCmd && format != sshutil.FormatConfig {
    return fmt.Errorf("unsupported format %q", format)
}

Type guard

func validFormat(f sshutil.FormatT) bool { return f == sshutil.FormatCmd || f == sshutil.FormatConfig }

Try / catch

if err := sshutil.Format(w, sshPath, instName, format, opts); err != nil {
    if strings.Contains(err.Error(), "unknown format") {
        // fall back to sshutil.FormatConfig
    }
}

Prevention

When it happens

Trigger: Passing a FormatT value that is neither "cmd" nor "config" (zero-value struct/empty string, wrong constant, or a value produced by unvalidated user input) to sshutil.Format.

Common situations: Constructing FormatT from CLI flags or config files without validation; refactoring that renames the constants; uninitialized variables defaulting to the zero value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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