{"record":{"id":"d73ecb25608c5dbc","repo":"lima-vm/lima","slug":"failed-to-detect-the-format-of-q-w","errorCode":null,"errorMessage":"failed to detect the format of %#q: %w","messagePattern":"failed to detect the format of %#q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/vz/vm_darwin.go","lineNumber":537,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tconfigurations = append(configurations, networkConfig)\n\t\t}\n\t}\n\tvmConfig.SetNetworkDevicesVirtualMachineConfiguration(configurations)\n\treturn nil\n}\n\nfunc validateDiskFormat(diskPath string) error {\n\tf, err := os.Open(diskPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\timg, err := qcow2reader.Open(f)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to detect the format of %#q: %w\", diskPath, err)\n\t}\n\tsupportedDiskTypes := []image.Type{raw.Type, asif.Type}\n\tif t := img.Type(); !slices.Contains(supportedDiskTypes, t) {\n\t\treturn fmt.Errorf(\"expected the format of %#q to be one of %v, got %#q\", diskPath, supportedDiskTypes, t)\n\t}\n\t// TODO: ensure that the disk is formatted with GPT or ISO9660\n\treturn nil\n}\n\nfunc attachDisks(ctx context.Context, inst *limatype.Instance, vmConfig *vz.VirtualMachineConfiguration) error {\n\tdiskPath := filepath.Join(inst.Dir, filenames.Disk)\n\tisoPath := filepath.Join(inst.Dir, filenames.ISO)\n\tciDataPath := filepath.Join(inst.Dir, filenames.CIDataISO)\n\tvar configurations []vz.StorageDeviceConfiguration\n\n\tif osutil.FileExists(diskPath) {\n\t\tif err := validateDiskFormat(diskPath); err != nil {\n\t\t\treturn err","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/vz/vm_darwin.go#L519-L555","documentation":"validateDiskFormat opens the disk image and asks qcow2reader to detect its format; if the file is unreadable as a known image format (or I/O fails), Lima wraps the underlying error. This means the additional disk / cidata file passed to the vz driver is not a recognizable disk image.","triggerScenarios":"attachDisks -> validateDiskFormat on a disk path whose file is corrupted, empty, truncated, or in an unsupported format that qcow2reader.Open cannot sniff.","commonSituations":"Interrupted download/copy of a disk image; a placeholder or text file at the disk path; disk created by another tool in a format qcow2reader does not detect; permission/IO error during open that surfaces after Open.","solutions":["Inspect the file (`file <path>`, `qemu-img info`) and re-create or re-download the disk image in a supported format","Ensure the path passed as additional disk actually points to the data disk (datadisk file) and is non-empty","Delete the instance/disk store entry and let Lima recreate the disk"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"f, err := os.Open(diskPath)\nif err != nil { return err }\nmagic := make([]byte, 8)\nf.Read(magic)\n// verify magic matches a known image type or run `file diskPath` before attach","typeGuard":null,"tryCatchPattern":"if err := limactlStart(cfg); err != nil {\n    if strings.Contains(err.Error(), \"failed to detect the format\") {\n        // re-download / recreate the disk image\n    }\n}","preventionTips":["Verify disk images with `file`/`qemu-img info` before attaching","Check download checksums so truncated images are caught early","Never point additionalDisks at manually created placeholder files"],"tags":["disk-image","vz-driver","format-detection"],"backgroundTag":"disk-image-format-unrecognized","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}