{"id":"33cfe671439302da","repo":"gohugoio/hugo","slug":"invalid-modules-list-q","errorCode":null,"errorMessage":"invalid modules list: %q","messagePattern":"invalid modules list: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/collect.go","lineNumber":625,"sourceCode":"\n\t\treturn err\n\t}\n\n\tdefer f.Close()\n\n\tscanner := bufio.NewScanner(f)\n\n\tfor scanner.Scan() {\n\t\t// # github.com/alecthomas/chroma v0.6.3\n\t\tline := scanner.Text()\n\t\tline = strings.Trim(line, \"# \")\n\t\tline = strings.TrimSpace(line)\n\t\tif line == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tparts := strings.Fields(line)\n\t\tif len(parts) != 2 {\n\t\t\treturn fmt.Errorf(\"invalid modules list: %q\", filename)\n\t\t}\n\t\tpath := parts[0]\n\n\t\tshouldAdd := c.Client.moduleConfig.VendorClosest\n\n\t\tif !shouldAdd {\n\t\t\tif _, found := c.vendored[path]; !found {\n\t\t\t\tshouldAdd = true\n\t\t\t}\n\t\t}\n\n\t\tif shouldAdd {\n\t\t\tc.vendored[path] = vendoredModule{\n\t\t\t\tOwner:   owner,\n\t\t\t\tDir:     filepath.Join(vendorDir, path),\n\t\t\t\tVersion: parts[1],\n\t\t\t}\n\t\t}","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/modules/collect.go#L607-L643","documentation":"When reading a vendor manifest (`_vendor/modules.txt`) in modules/collect.go:625, each non-empty line must have exactly two fields: `# <modulepath> <version>`. A line that trims to anything else fails parsing and Hugo aborts with `invalid modules list: %q`, naming the file. This protects against corrupted or hand-edited vendor metadata silently producing a wrong module set.","triggerScenarios":"`collector` parsing `_vendor/modules.txt` during collection when any line has fewer or more than two whitespace-separated fields after stripping the `# ` prefix — e.g. a module path with no version, extra tokens, or merge-conflict markers.","commonSituations":"Git merge conflicts leaving `<<<<<<<` markers inside `_vendor/modules.txt`; manual edits to the vendor manifest; line corruption from CRLF/encoding mangling; concatenated files from bad scripts.","solutions":["Regenerate the vendor tree: delete `_vendor` (or fix modules.txt) and run `hugo mod vendor`.","Open the named modules.txt and remove malformed lines/conflict markers — each line must be `# path version`.","Resolve any git merge conflicts in `_vendor` by re-vendoring rather than hand-merging.","Avoid manual edits to `_vendor/modules.txt`; treat it as generated output."],"exampleFix":"# before (_vendor/modules.txt)\n# github.com/alecthomas/chroma\n<<<<<<< HEAD\n# after: regenerate\nrm -rf _vendor\nhugo mod vendor","handlingStrategy":"validation","validationCode":"switch v := cfg.Get(\"module.imports\").(type) {\ncase []interface{}, []map[string]interface{}:\n    // ok\ndefault:\n    return fmt.Errorf(\"module.imports must be a list, got %T\", v)\n}","typeGuard":"func isImportsList(v interface{}) bool {\n    _, ok := v.([]interface{})\n    return ok\n}","tryCatchPattern":null,"preventionTips":["In TOML/YAML config, declare imports as an array of tables ([[module.imports]]), not a scalar or map","Lint config files in CI with `hugo config` before building","When generating config programmatically, marshal from typed structs rather than hand-built maps"],"tags":["hugo-modules","vendoring","parsing","git"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}