lima-vm/lima · error

failed to build network arguments: %w

Error message

failed to build network arguments: %w

What it means

Cmdline delegates all network device flag construction to buildNetworkArgs; any error returned there (invalid network spec, missing socket_vmnet, socket path failures, usernet socket errors) is wrapped as `failed to build network arguments: %w`. It is a generic wrapper meaning 'the instance's networks config could not be translated into krunkit --device flags'.

Source

Thrown at pkg/driver/krunkit/krunkit_darwin_arm64.go:86

			if disk.Instance != "" {
				return nil, fmt.Errorf("failed to run attach disk %#q, in use by instance %#q", disk.Name, disk.Instance)
			}
			if lerr := disk.Lock(inst.Dir); lerr != nil {
				return nil, fmt.Errorf("failed to lock disk %#q: %w", d.Name, lerr)
			}
			extraDiskPath := filepath.Join(disk.Dir, filenames.DataDisk)
			logrus.Infof("Mounting disk %#q on %#q", disk.Name, disk.MountPoint)
			if cerr := diskUtil.Convert(ctx, raw.Type, extraDiskPath, extraDiskPath, nil, true); cerr != nil {
				return nil, fmt.Errorf("failed to convert extra disk %#q to raw: %w", extraDiskPath, cerr)
			}
			args = append(args, "--device", fmt.Sprintf("virtio-blk,path=%s,format=raw", extraDiskPath))
		}
	}

	// Network commands
	networkArgs, err := buildNetworkArgs(inst)
	if err != nil {
		return nil, fmt.Errorf("failed to build network arguments: %w", err)
	}

	// File sharing commands
	if *inst.Config.MountType == limatype.VIRTIOFS {
		for _, mount := range inst.Config.Mounts {
			if _, err := os.Stat(mount.Location); errors.Is(err, os.ErrNotExist) {
				if err := os.MkdirAll(mount.Location, 0o750); err != nil {
					return nil, err
				}
			}
			tag := limayaml.MountTag(mount.Location, *mount.MountPoint)
			mountArg := fmt.Sprintf("virtio-fs,sharedDir=%s,mountTag=%s", mount.Location, tag)
			args = append(args, "--device", mountArg)
		}
	}

	args = append(args, networkArgs...)

View on GitHub (pinned to dd909d0973)

Solutions

  1. Inspect the wrapped `%w` cause and fix accordingly (install socket_vmnet, fix the network name, etc.).
  2. Validate `networks:` entries in the instance lima.yaml: each needs either a valid `lima:` mode (shared/bridged/user-v2) or a `socket:` path.
  3. Check ~/.lima/_config/networks.yaml defines any named networks referenced by the instance.
  4. If only basic connectivity is needed, remove custom networks entries so the default slirp/usernet path is used.

Example fix

# before (lima.yaml)
networks:
  - lima: shared   # socket_vmnet missing
# after
networks:
  - lima: user-v2
# or install socket_vmnet: brew install socket_vmnet + limactl sudoers
Defensive patterns

Strategy: try-catch

Validate before calling

# Shell: sanity-check network entries before start
yq '.networks[] | select((.lima == null) and (.socket == null))' lima.yaml | grep . && { echo "network entry missing lima/socket"; exit 1; }

Type guard

func validNetworkSpec(nw Network) bool {
    return nw.Lima == "user-v2" || nw.Lima == "shared" || nw.Lima == "bridged" || nw.Socket != ""
}

Try / catch

if _, err := d.Cmdline(inst); err != nil {
    if cause := errors.Unwrap(err); cause != nil {
        log.Errorf("network config problem: %v", cause) // inspect wrapped cause
    }
    return err
}

Prevention

When it happens

Trigger: Calling Start/Cmdline on an instance whose networks array contains a spec buildNetworkArgs rejects (unknown nw.Lima mode, neither Lima nor Socket set), socket_vmnet not installed for shared/bridged mode, or usernet/socket path resolution failing.

Common situations: Misconfigured `networks:` entries in lima.yaml; referencing a named network not defined in networks.yaml; socket_vmnet absent on macOS; typo'd socket path. The useful detail is in the wrapped cause.

Related errors


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