{"record":{"id":"ec47d94ef5743884","repo":"lima-vm/lima","slug":"invalid-value-for-number-of-cpus-must-be-0","errorCode":null,"errorMessage":"invalid value for number of cpus, must be >= 0","messagePattern":"invalid value for number of cpus, must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/editflags/editflags.go","lineNumber":232,"sourceCode":"// YQExpressions returns YQ expressions.\nfunc YQExpressions(flags *flag.FlagSet, newInstance bool, params map[string]string) ([]string, error) {\n\ttype def struct {\n\t\tflagName                 string\n\t\texprFunc                 func(*flag.Flag) ([]string, error)\n\t\tonlyValidForNewInstances bool\n\t\texperimental             bool\n\t}\n\td := defaultExprFunc\n\tdefs := []def{\n\t\t{\n\t\t\t\"cpus\",\n\t\t\tfunc(_ *flag.Flag) ([]string, error) {\n\t\t\t\tnumCpus, err := flags.GetInt(\"cpus\")\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tif numCpus < 0 {\n\t\t\t\t\treturn nil, errors.New(\"invalid value for number of cpus, must be >= 0\")\n\t\t\t\t}\n\t\t\t\treturn []string{fmt.Sprintf(\".cpus = %d\", numCpus)}, nil\n\t\t\t},\n\t\t\tfalse,\n\t\t\tfalse,\n\t\t},\n\t\t{\n\t\t\t\"dns\",\n\t\t\tfunc(_ *flag.Flag) ([]string, error) {\n\t\t\t\tipSlice, err := flags.GetIPSlice(\"dns\")\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tips := make([]string, len(ipSlice))\n\t\t\t\tfor i, ip := range ipSlice {\n\t\t\t\t\tips[i] = `\"` + ip.String() + `\"`\n\t\t\t\t}\n\t\t\t\texpr := fmt.Sprintf(\".dns += [%s] | .dns |= unique | .hostResolver.enabled=false\", strings.Join(ips, \",\"))","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/editflags/editflags.go#L214-L250","documentation":"When building yq expressions for the --cpus flag, YQExpressions reads the flag value with flags.GetInt and rejects negative numbers because a VM cannot have a negative CPU count. This error is returned when --cpus is set to a value below 0.","triggerScenarios":"Running limactl create/edit with --cpus=-1 (or any negative integer); a script computing a CPU count that yields a negative value.","commonSituations":"Scripts using arithmetic that underflows (e.g. counting CPUs and subtracting); users typing '-1' intending 'auto/unlimited'; copying a dash into the value.","solutions":["Pass a non-negative integer: --cpus 0 or a positive count (0 means leave/default behavior)","Fix the script's CPU-count calculation so it cannot go negative","Omit --cpus entirely to keep the template default"],"exampleFix":"// before\nlimactl create template://_default --cpus=-1\n// after\nlimactl create template://_default --cpus=4","handlingStrategy":"validation","validationCode":"cpus, _ := flags.GetInt(\"cpus\")\nif cpus < 0 {\n\treturn fmt.Errorf(\"--cpus must be >= 0, got %d\", cpus)\n}","typeGuard":"func validCpuCount(n int) bool {\n\treturn n >= 0\n}","tryCatchPattern":"exprs, err := editflags.YQExpressions(flagSet, newInstance, params)\nif err != nil {\n\tif strings.Contains(err.Error(), \"number of cpus\") {\n\t\treturn fmt.Errorf(\"fix --cpus: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Never pass negative integers to --cpus","Sanitize script-computed values before passing them as flags","Treat 0 or omission as 'use default' rather than -1 as 'unlimited'"],"tags":["cli","cpu","validation","lima"],"backgroundTag":"invalid-numeric-flag-value","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}