{"record":{"id":"e51f9e536649f9eb","repo":"lima-vm/lima","slug":"failed-to-protect-instance-q-w","errorCode":null,"errorMessage":"failed to protect instance %#q: %w","messagePattern":"failed to protect instance %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/protect.go","lineNumber":44,"sourceCode":"\t}\n\treturn protectCommand\n}\n\nfunc protectAction(cmd *cobra.Command, args []string) error {\n\tctx := cmd.Context()\n\tvar errs []error\n\tfor _, instName := range args {\n\t\tinst, err := store.Inspect(ctx, instName)\n\t\tif err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to inspect instance %#q: %w\", instName, err))\n\t\t\tcontinue\n\t\t}\n\t\tif inst.Protected {\n\t\t\tlogrus.Warnf(\"Instance %#q is already protected. Skipping.\", instName)\n\t\t\tcontinue\n\t\t}\n\t\tif err := inst.Protect(); err != nil {\n\t\t\terrs = append(errs, fmt.Errorf(\"failed to protect instance %#q: %w\", instName, err))\n\t\t\tcontinue\n\t\t}\n\t\tlogrus.Infof(\"Protected %#q\", instName)\n\t}\n\treturn errors.Join(errs...)\n}\n\nfunc protectBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {\n\treturn bashCompleteInstanceNames(cmd)\n}\n","sourceCodeStart":26,"sourceCodeEnd":55,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/protect.go#L26-L55","documentation":"After inspection succeeds, protectAction calls inst.Protect(), which writes the protection marker into the instance directory. If that filesystem operation fails (permissions, disk, concurrent modification), the error is wrapped as \"failed to protect instance\" and joined into the aggregate error at the end.","triggerScenarios":"`limactl protect <name>` where inst.Protect() fails: read-only LIMA_HOME, permission changes on ~/.lima, disk full, or the instance directory mutated between inspect and protect.","commonSituations":"Running limactl as a different user than the instance owner; root-owned files after sudo usage; read-only mounts/NFS home directories; antivirus or sync tools locking files.","solutions":["Fix permissions on the instance directory under LIMA_HOME (chown/chmod back to the invoking user)","Re-run the protect command after resolving the filesystem issue","Check disk space and that LIMA_HOME is on a writable filesystem"],"exampleFix":"// before\nsudo limactl protect ubuntu   # creates root-owned state / permission mismatch\n// after\nlimactl protect ubuntu        # run as the instance-owning user","handlingStrategy":"try-catch","validationCode":"test -w ~/.lima/instances/$inst || { echo \"instance dir not writable\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := protectCmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"failed to protect instance\") {\n        // check permissions/ownership of the instance dir, disk space, then retry\n    }\n}","preventionTips":["Run limactl as the same user that owns the instance directory","Keep LIMA_HOME on a local writable filesystem, not NFS/ro mounts","Avoid sudo for limactl commands to prevent ownership mismatches"],"tags":["instance","protect","filesystem"],"backgroundTag":"instance-protect-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}