{"record":{"id":"09a449d7e527b0eb","repo":"lima-vm/lima","slug":"failed-to-inspect-instance-q-w","errorCode":null,"errorMessage":"failed to inspect instance %#q: %w","messagePattern":"failed to inspect instance %#q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/protect.go","lineNumber":36,"sourceCode":"\t\tUse:   \"protect INSTANCE [INSTANCE, ...]\",\n\t\tShort: \"Protect an instance to prohibit accidental removal\",\n\t\tLong: `Protect an instance to prohibit accidental removal via the 'limactl delete' command.\nThe instance is not being protected against removal via '/bin/rm', Finder, etc.`,\n\t\tArgs:              WrapArgsError(cobra.MinimumNArgs(1)),\n\t\tRunE:              protectAction,\n\t\tValidArgsFunction: protectBashComplete,\n\t\tGroupID:           advancedCommand,\n\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}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/protect.go#L18-L54","documentation":"protectAction calls store.Inspect for each named instance; when the instance directory/yaml cannot be read or parsed, the error is wrapped as \"failed to inspect instance\" and collected (other instances still processed). It almost always wraps an os.ErrNotExist for a nonexistent instance name.","triggerScenarios":"`limactl protect <name>` where <name> has no instance directory under LIMA_HOME; corrupted/missing lima.yaml; wrong LIMA_HOME pointing at a different instance set.","commonSituations":"Typo in instance name; running protect before `limactl start` created the instance; pointing LIMA_HOME at a non-default location; partially deleted instance directory.","solutions":["Check the name with `limactl list` and re-run protect with the exact instance name","Create the instance first (`limactl start <template> --name <name>`) before protecting","If LIMA_HOME is customized, ensure it matches the environment used to create the instance"],"exampleFix":"// before\nlimactl protect ubunty\n// after\nlimactl list\nlimactl protect ubuntu","handlingStrategy":"try-catch","validationCode":"limactl list | grep -qx \"$inst\" || { echo \"instance $inst not found\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"err := protectCmd.Run()\nif err != nil && strings.Contains(err.Error(), \"failed to inspect instance\") {\n    // instance missing: create it or fix the name/LIMA_HOME\n}\nif errors.Is(err, os.ErrNotExist) { /* name typo or wrong LIMA_HOME */ }","preventionTips":["Verify instance names with `limactl list` before protect/unprotect","Set LIMA_HOME explicitly and consistently in scripts","Create instances before attempting to protect them"],"tags":["instance","inspect","not-found"],"backgroundTag":"instance-not-found","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}