{"record":{"id":"0d04337df83c5b5b","repo":"hashicorp/nomad","slug":"error-reading-q-w","errorCode":null,"errorMessage":"Error reading %q: %w","messagePattern":"Error reading %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_lock.go","lineNumber":304,"sourceCode":"\tvar path string\n\n\t// Handle first argument:  @file or «var path»\n\targ := args[0]\n\n\tswitch {\n\tcase isArgFileRef(arg):\n\t\t// ArgFileRefs start with \"@\" so we need to peel that off\n\t\t// detect format based on file extension\n\t\tspecPath := arg[1:]\n\t\terr = c.varPutCommand.setParserForFileArg(specPath)\n\t\tif err != nil {\n\t\t\treturn \"\", args, err\n\t\t}\n\n\t\tc.varPutCommand.verbose(fmt.Sprintf(\"Reading whole variable specification from %q\", specPath))\n\t\tc.varPutCommand.contents, err = os.ReadFile(specPath)\n\t\tif err != nil {\n\t\t\treturn \"\", args, fmt.Errorf(\"Error reading %q: %w\", specPath, err)\n\t\t}\n\tdefault:\n\t\tpath = sanitizePath(arg)\n\t\tc.varPutCommand.verbose(fmt.Sprintf(\"Writing to path %q\", path))\n\t}\n\n\t// Handle second argument: can @file, or child process\n\targs = args[1:]\n\tswitch {\n\tcase isArgFileRef(args[0]):\n\t\targ := args[0]\n\n\t\terr = c.varPutCommand.setParserForFileArg(arg)\n\t\tif err != nil {\n\t\t\treturn \"\", args, err\n\t\t}\n\n\t\tc.varPutCommand.verbose(fmt.Sprintf(\"Creating variable %q from specification file %q\", path, arg))","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_lock.go#L286-L322","documentation":"In the 'var put' flow, an argument like '@specfile' (or the designated spec path) makes the command read the entire variable specification from that file via os.ReadFile. This error wraps the read failure with the offending path, preserving the underlying OS error through %w.","triggerScenarios":"Running `waypoint var put @myspec.hcl` (or the equivalent readPathFromArgs path) where myspec.hcl does not exist, is unreadable, or is a directory. Raised from readPathFromArgs during Run.","commonSituations":"Typo'd spec file names; executing the command from a different working directory than the spec file's location; CI checkouts where the spec file was not committed or not yet generated; permission-restricted files.","solutions":["Verify the spec file path exists relative to the current working directory and is a regular file (ls -la <path>)","Use an absolute path to eliminate CWD ambiguity","Check read permissions for the invoking user, especially in CI containers","If the spec is generated by an earlier step, ensure that step completed before running var put"],"exampleFix":"// before\nwaypoint var put @deploy.vars   // deploy.vars missing in CI workspace\n// after\nwaypoint var put @${CI_WORKSPACE}/deploy.vars   // absolute, verified to exist","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(specPath); err != nil {\n\t// fail fast: spec file missing\n} else if fi.IsDir() {\n\t// fail fast: spec path is a directory\n}","typeGuard":null,"tryCatchPattern":"contents, err := os.ReadFile(specPath)\nif err != nil {\n\tif errors.Is(err, fs.ErrNotExist) { /* generate or locate spec */ }\n\tif errors.Is(err, fs.ErrPermission) { /* fix permissions */ }\n}","preventionTips":["Verify the spec file exists in the working directory before invoking var put","Use absolute paths in CI pipelines","Ensure upstream steps that generate the spec complete first","Confirm the file is committed/generated in ephemeral CI workspaces"],"tags":["cli","file-io","var-put"],"backgroundTag":"file-read-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}