abiosoft/colima · error

error decoding networks into struct: %w

Error message

error decoding networks into struct: %w

What it means

The JSON output of guest 'sudo incus network list --format json' could not be unmarshalled into []networkInfo. The incus daemon in the guest emitted JSON whose shape does not match colima's struct — typically a guest incus version newer or older than the schema colima was built against.

Source

Thrown at environment/container/incus/incus.go:395

}

func (c incusRuntime) addDockerRemote() error {
	if c.hasRemote("docker") {
		// already added
		return nil
	}

	return c.host.RunQuiet("incus", "remote", "add", "docker", "https://docker.io", "--protocol=oci")
}

func (c incusRuntime) findNetwork(interfaceName string) (found bool, info networkInfo, err error) {
	b, err := c.guest.RunOutput("sudo", "incus", "network", "list", "--format", "json")
	if err != nil {
		return found, info, fmt.Errorf("error listing networks: %w", err)
	}
	var resp []networkInfo
	if err := json.NewDecoder(strings.NewReader(b)).Decode(&resp); err != nil {
		return found, info, fmt.Errorf("error decoding networks into struct: %w", err)
	}
	for _, n := range resp {
		if n.Name == interfaceName {
			return true, n, nil
		}
	}

	return
}

//go:embed config.yaml
var configYaml string

type remoteInfo map[string]struct {
	Addr string `json:"Addr"`
}

type networkInfo struct {

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Inspect the raw output: 'colima ssh -- sudo incus network list --format json' and compare to colima's networkInfo fields
  2. Align versions: upgrade colima, or recreate the VM so guest incus matches: 'colima delete && colima start'
  3. Update guest incus inside the VM to the version colima supports
  4. Report the schema diff as a colima issue if versions match and it still fails
Defensive patterns

Strategy: validation

Validate before calling

// decode leniently: strict=false tolerates added fields from newer incus
dec := json.NewDecoder(strings.NewReader(b))
dec.DisallowUnknownFields() // remove this if set; default decode ignores unknown fields
var resp []networkInfo
if err := dec.Decode(&resp); err != nil {
    return found, info, fmt.Errorf("error decoding networks into struct: %w", err)
}

Try / catch

var resp []networkInfo
if err := json.Unmarshal([]byte(b), &resp); err != nil {
    if !json.Valid([]byte(b)) {
        return found, info, fmt.Errorf("guest incus emitted non-JSON (version skew?): %w", err)
    }
    return found, info, fmt.Errorf("schema mismatch, align colima and guest incus: %w", err)
}

Prevention

When it happens

Trigger: json.Decode into []networkInfo fails: guest incus output schema changed (field types/names), non-JSON prefix in output, or truncated output when the SSH stream breaks mid-read.

Common situations: Guest VM image shipped with an incus version different from the one colima expects (version skew after upgrading colima without recreating the VM), custom guest images with a different incus build.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/343f32eb1f988c8e. Report an issue: GitHub.