{"record":{"id":"97c6138ffd6f2dd1","repo":"hashicorp/nomad","slug":"error-reading-q-s","errorCode":null,"errorMessage":"error reading %q: %s","messagePattern":"error reading %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/var_lock.go","lineNumber":326,"sourceCode":"\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))\n\t\tfPath := arg[1:]\n\t\tc.varPutCommand.contents, err = os.ReadFile(fPath)\n\t\tif err != nil {\n\t\t\treturn \"\", args, fmt.Errorf(\"error reading %q: %s\", fPath, err)\n\t\t}\n\t\targs = args[1:]\n\tdefault:\n\t\t// no-op - should be child process\n\t}\n\n\treturn path, args, nil\n}\n\n// script returns a command to execute a script through a shell.\nfunc script(ctx context.Context, args []string) (*exec.Cmd, error) {\n\tshell := \"/bin/sh\"\n\n\tif other := os.Getenv(\"SHELL\"); other != \"\" {\n\t\tshell = other\n\t}\n\n\treturn exec.CommandContext(ctx, shell, \"-c\", strings.Join(args, \" \")), nil","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/var_lock.go#L308-L344","documentation":"readPathFromArgs in nomad's `var put` command reads a specification file passed with the `@file` argument syntax via os.ReadFile. When the file cannot be opened or read (missing path, permission denied, path is a directory), the command aborts by wrapping the underlying OS error in `error reading %q: %s`. The %q is the path with the leading `@` stripped.","triggerScenarios":"Running `nomad var put ... @spec.json` (or `var init`-style flows) where: the spec file does not exist at fPath; the path points to a directory instead of a file; the process lacks read permission on the file; or the file was deleted between argument parsing and read time.","commonSituations":"Typo in the spec filename; running from a different working directory than expected; CI pipelines that forget to check out or generate the spec file; relative paths that break after `cd`; secrets files mounted with wrong permissions in containers.","solutions":["Verify the file exists at the exact path: `ls -l <path>` and correct any typo or run from the right directory.","Check read permissions on the file (`chmod +r`) and that it is a regular file, not a directory.","In CI, ensure the spec file is created/checked out before the nomad command runs (add a dependency or explicit generation step).","Use an absolute path to avoid working-directory surprises."],"exampleFix":"// before\nnomad var put -path app/config @app-config.hcl\n// after (file confirmed to exist first)\nls app-config.hcl && nomad var put -path app/config @./app-config.hcl","handlingStrategy":"validation","validationCode":"if [ ! -f \"${SPEC_PATH}\" ]; then echo \"spec file missing: ${SPEC_PATH}\" >&2; exit 1; fi\n[ -r \"${SPEC_PATH}\" ] || { echo \"spec file not readable: ${SPEC_PATH}\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := runNomadVarPut(args...); err != nil && strings.HasPrefix(err.Error(), \"error reading \") {\n    // inspect wrapped *os.PathError via errors.As and report the path\n    var perr *os.PathError\n    if errors.As(err, &perr) { log.Fatalf(\"cannot read %s: %v\", perr.Path, perr.Err) }\n}","preventionTips":["Use absolute paths for spec files in scripts and CI.","Add a pre-flight existence/readability check before invoking nomad.","Ensure CI checks out or generates the spec file before nomad steps."],"tags":["cli","file-io","nomad","variables"],"backgroundTag":"file-not-found","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"}