lima-vm/lima · error

expected status %#q, got %#q

Error message

expected status %#q, got %#q

What it means

pkg/instance.Delete only removes instances whose status is StatusStopped unless force=true. This error reports the mismatch, quoting the expected and actual status via %#q (e.g. "Running"). It prevents deleting a live VM whose guestagent is still running.

Source

Thrown at pkg/instance/delete.go:22

package instance

import (
	"context"
	"errors"
	"fmt"
	"os"

	"github.com/lima-vm/lima/v2/pkg/driver/external/server"
	"github.com/lima-vm/lima/v2/pkg/driverutil"
	"github.com/lima-vm/lima/v2/pkg/limatype"
)

func Delete(ctx context.Context, inst *limatype.Instance, force bool) error {
	if inst.Protected {
		return errors.New("instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)")
	}
	if !force && inst.Status != limatype.StatusStopped {
		return fmt.Errorf("expected status %#q, got %#q", limatype.StatusStopped, inst.Status)
	}

	StopForcibly(inst)

	if len(inst.Errors) == 0 {
		if err := unregister(ctx, inst); err != nil {
			return fmt.Errorf("failed to unregister %#q: %w", inst.Dir, err)
		}
	}
	if err := os.RemoveAll(inst.Dir); err != nil {
		return fmt.Errorf("failed to remove %#q: %w", inst.Dir, err)
	}

	return nil
}

func unregister(ctx context.Context, inst *limatype.Instance) error {
	limaDriver, err := driverutil.CreateConfiguredDriver(ctx, inst, 0)

View on GitHub (pinned to dd909d0973)

Solutions

  1. Stop the instance first: `limactl stop <instance>`, then delete.
  2. Pass force=true (`limactl delete --force <instance>`) to delete regardless of status.
  3. If the status is stale (VM is actually dead), refresh with `limactl list` or force-delete.

Example fix

// before
limactl delete myvm
// after
limactl stop myvm && limactl delete myvm
Defensive patterns

Strategy: validation

Validate before calling

inst, _ := store.Inspect(ctx, instName)
if inst.Status != limatype.StatusStopped {
    if err := instance.StopForciblyWait(ctx, inst); err != nil {
        return err
    }
}

Try / catch

if err := instance.Delete(ctx, inst, false); err != nil {
    if strings.Contains(err.Error(), "expected status") {
        // stop first, then retry
        return instance.Delete(ctx, inst, true)
    }
    return err
}

Prevention

When it happens

Trigger: instance.Delete(ctx, inst, false) where inst.Status != limatype.StatusStopped — typically the instance is Running, and inst.Protected is false.

Common situations: Deleting a VM that is still booted or starting; stale status in lima.yaml after a crashed hostagent; a scheduler deleting instances without stopping them first.

Related errors


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