{"record":{"id":"9d318b0736c4ee82","repo":"direnv/direnv","slug":"line-d-w","errorCode":null,"errorMessage":"line %d: %w","messagePattern":"line (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cmd_watch_list.go","lineNumber":59,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Read `mtime path` lines from stdin\n\treader := bufio.NewReader(os.Stdin)\n\n\ti := 1\n\tfor {\n\t\tline, err := reader.ReadString('\\n')\n\t\tif err == nil {\n\t\t\telems := strings.SplitN(line, \" \", 2)\n\t\t\tif len(elems) != 2 {\n\t\t\t\treturn fmt.Errorf(\"line %d: expected to contain two elements\", i)\n\t\t\t}\n\t\t\tmtime, err := strconv.Atoi(elems[0])\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"line %d: %w\", i, err)\n\t\t\t}\n\t\t\tpath := elems[1][:len(elems[1])-1]\n\n\t\t\t// add to watches\n\t\t\terr = watches.NewTime(path, int64(mtime), true)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t} else if errors.Is(err, io.EOF) {\n\t\t\tbreak\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"line %d: %w\", i, err)\n\t\t}\n\t\ti++\n\t}\n\n\te := make(ShellExport)\n\te.Add(DIRENV_WATCHES, watches.Marshal())","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/direnv/direnv/blob/b00e451f547f39be7ab836d969054114a465a0f9/internal/cmd/cmd_watch_list.go#L41-L77","documentation":"While parsing DIRENV_WATCHES, each line's first field must be an integer mtime parsed by strconv.Atoi. If it is not numeric (or overflows int), the parse error is wrapped with the offending line number via `line %d: %w`, preserving the underlying strconv error (e.g. `strconv.Atoi: parsing \"abc\": invalid syntax`).","triggerScenarios":"A DIRENV_WATCHES line whose first space-delimited field is not an integer — e.g. 'abc /some/path', a path placed before the mtime, or a float/negative-garbage mtime in a hand-edited or corrupted variable.","commonSituations":"Manually constructing the watch string with fields in the wrong order; scripts appending watches with unformatted timestamps; corruption from shell quoting stripping digits; copy-paste edits of the env var.","solutions":["Clear and rebuild: `unset DIRENV_WATCHES`, then `direnv reload` and re-run the watch commands.","Inspect the variable and fix the offending line so it is '<integer-mtime> <path>'.","Re-create watches with the official commands (`direnv watch <file>`) rather than hand-crafting the value.","Read the wrapped strconv message in the error to identify the exact bad token on the reported line."],"exampleFix":"// before (wrong field order)\nexport DIRENV_WATCHES=\"/some/path 1600000000\"\n// after\nexport DIRENV_WATCHES=\"1600000000 /some/path\"","handlingStrategy":"validation","validationCode":"# check the first field of every DIRENV_WATCHES line is numeric\nwhile IFS=' ' read -r mtime rest; do\n  [ -n \"$rest\" ] || continue\n  case \"$mtime\" in ''|*[!0-9]*) echo \"bad mtime: $mtime\" >&2; exit 1 ;; esac\ndone <<< \"${DIRENV_WATCHES:-}\"","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"direnv\", \"watch-list\", shell).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"invalid syntax\") {\n    os.Unsetenv(\"DIRENV_WATCHES\")\n    return fmt.Errorf(\"DIRENV_WATCHES had non-numeric mtime; cleared: %s\", out)\n}","preventionTips":["Keep mtime first and path second on each watch line.","Use direnv's own watch commands to build the value rather than manual export.","Clear and rebuild DIRENV_WATCHES after any manual env manipulation.","Read the wrapped strconv message to locate the exact bad token and line."],"tags":["cli","parsing","env-var","corruption"],"backgroundTag":"malformed-environment-data","analyzedSha":"b00e451f547f39be7ab836d969054114a465a0f9","analyzedAt":"2026-09-05T21:39:49.983Z","contentChangedAt":"2026-09-05T21:39:49.983Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}