{"record":{"id":"1f564a3f60107cc3","repo":"lima-vm/lima","slug":"field-mounts-d-location-refers-to-an-unexpanda","errorCode":null,"errorMessage":"field `mounts[%d].location` refers to an unexpandable path: %#q: %w","messagePattern":"field `mounts\\[(.+?)\\]\\.location` refers to an unexpandable path: %#q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/limayaml/validate.go","lineNumber":132,"sourceCode":"\tif _, err := units.RAMInBytes(*y.Disk); err != nil {\n\t\terrs = errors.Join(errs, fmt.Errorf(\"field `disk` has an invalid value: %w\", err))\n\t}\n\n\tfor i, disk := range y.AdditionalDisks {\n\t\tif err := identifiers.Validate(disk.Name); err != nil {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `additionalDisks[%d].name is invalid`: %w\", i, err))\n\t\t}\n\t}\n\n\tfor i, f := range y.Mounts {\n\t\tif !filepath.IsAbs(f.Location) && !strings.HasPrefix(f.Location, \"~\") {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `mounts[%d].location` must be an absolute path, got %#q\",\n\t\t\t\ti, f.Location))\n\t\t}\n\t\t// f.Location has already been expanded in FillDefaults(), but that function cannot return errors.\n\t\tloc, err := localpathutil.Expand(f.Location)\n\t\tif err != nil {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `mounts[%d].location` refers to an unexpandable path: %#q: %w\", i, f.Location, err))\n\t\t}\n\t\tst, err := os.Stat(loc)\n\t\tif err != nil {\n\t\t\tif !errors.Is(err, os.ErrNotExist) {\n\t\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `mounts[%d].location` refers to an inaccessible path: %#q: %w\", i, f.Location, err))\n\t\t\t}\n\t\t\tif warn {\n\t\t\t\tlogrus.Warnf(\"field `mounts[%d].location` refers to a non-existent directory: %#q:\", i, f.Location)\n\t\t\t}\n\t\t} else if !st.IsDir() {\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `mounts[%d].location` refers to a non-directory path: %#q: %w\", i, f.Location, err))\n\t\t}\n\n\t\tswitch *f.MountPoint {\n\t\tcase \"/\", \"/bin\", \"/dev\", \"/etc\", \"/home\", \"/opt\", \"/sbin\", \"/tmp\", \"/usr\", \"/var\":\n\t\t\terrs = errors.Join(errs, fmt.Errorf(\"field `mounts[%d].mountPoint` must not be a system path such as /etc or /usr\", i))\n\t\t// home directory defined in \"cidata.iso:/user-data\"\n\t\tcase *y.User.Home:","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/limayaml/validate.go#L114-L150","documentation":"After the absolute-path check, Validate() expands `~` in `mounts[i].location` using localpathutil.Expand. If expansion fails (e.g. malformed `~user` syntax or unresolvable user), this error wraps the Expand error.","triggerScenarios":"A mount location contains a tilde form that localpathutil.Expand cannot resolve, such as `~nonexistentuser/x`, when Validate runs.","commonSituations":"Typing `~otheruser/data` where that user does not exist on the host; malformed paths like `~` followed by unexpected characters; HOME unset in odd environments.","solutions":["Replace the unexpandable tilde path with a fully absolute path like `/home/otheruser/data`","Verify the target user/home exists on the host (`echo ~otheruser` in shell)","Re-validate the template after fixing"],"exampleFix":"// before\nmounts:\n  - location: ~nonexistentuser/data\n// after\nmounts:\n  - location: /home/realuser/data","handlingStrategy":"validation","validationCode":"const { execSync } = require('child_process')\nfunction expandableTilde(loc) {\n  if (!loc.startsWith('~')) return true\n  try { execSync(`echo ${loc}`, { shell: '/bin/sh', stdio: 'ignore' }); return true } catch { return false }\n}","typeGuard":"function isExpandableHomePath(p) { return typeof p === 'string' && (p === '~' || /^~(\\/|$)/.test(p)) } // avoid ~user forms unless the user exists","tryCatchPattern":"try { await limactl(['template','validate', file]) } catch (e) { if (/unexpandable path/.test(e.message)) { replaceTildeWithAbsolute(); } else throw e }","preventionTips":["Avoid `~user/...` forms; hardcode /home/user when needed","Test configs on the actual host user where HOME is set","Prefer absolute paths for cross-machine templates"],"tags":["lima","config-validation","path-expansion","mounts"],"backgroundTag":"unexpandable-path","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}