{"record":{"id":"7664b7ef1f961ce3","repo":"jdx/mise","slug":"go-module-metadata-contains-multiple-module-direct","errorCode":null,"errorMessage":"Go module metadata contains multiple module directives","messagePattern":"Go module metadata contains multiple module directives","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/workspace/go.rs","lineNumber":164,"sourceCode":"    }\n    Ok(directories)\n}\n\nfn read_module_path(context: &WorkspaceDiscoveryContext, path: &Path) -> Result<String> {\n    let contents = context\n        .read_to_string(path)\n        .wrap_err_with(|| format!(\"failed to read Go module metadata {}\", path.display()))?;\n    let mut module_path = None;\n\n    for (index, raw_line) in contents.lines().enumerate() {\n        let line = strip_comment(raw_line).trim();\n        let Some(arguments) = directive_arguments(line, \"module\") else {\n            continue;\n        };\n        let parsed = parse_argument(arguments)\n            .wrap_err_with(|| format!(\"invalid module directive on line {}\", index + 1))?;\n        if module_path.replace(parsed).is_some() {\n            bail!(\"Go module metadata contains multiple module directives\");\n        }\n    }\n\n    module_path.ok_or_else(|| eyre::eyre!(\"Go module metadata is missing a module directive\"))\n}\n\nfn directive_arguments<'a>(line: &'a str, directive: &str) -> Option<&'a str> {\n    let rest = line.strip_prefix(directive)?;\n    if !rest.starts_with(char::is_whitespace) {\n        return None;\n    }\n    Some(rest.trim())\n}\n\nfn parse_argument(value: &str) -> Result<String> {\n    if value.is_empty() {\n        bail!(\"directive requires one argument\");\n    }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/workspace/go.rs#L146-L182","documentation":"When reading a go.mod to learn its module path, mise allows exactly one `module` directive. If a second `module` line is found after one has already been parsed, it bails with 'Go module metadata contains multiple module directives'. Go itself also forbids this, so the file is invalid.","triggerScenarios":"A go.mod contains two or more `module <path>` lines — typically after a bad merge concatenated both sides, or a script appended a duplicate module directive.","commonSituations":"Unresolved git merge conflict in go.mod; copy-pasting a module line from another go.mod; code generators rewriting go.mod incorrectly.","solutions":["Delete the duplicate `module` directive so exactly one remains at the top of go.mod.","If go.mod came from a merge, rerun the merge resolving go.mod manually or `git checkout --theirs/--ours go.mod` then `go mod tidy`.","Run `go mod tidy` afterwards to normalize the file."],"exampleFix":"// before (go.mod)\nmodule example.com/old\nmodule example.com/new\n\n// after\nmodule example.com/new","handlingStrategy":"validation","validationCode":"// shell\n[ \"$(grep -cE '^module[ \\t]' go.mod)\" -eq 1 ] || { echo \"go.mod must have exactly one module directive\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match read_result {\n    Err(e) if e.to_string().contains(\"multiple module directives\") => {\n        eprintln!(\"go.mod corrupted (likely merge); run `git checkout --merge go.mod` or fix manually\");\n    }\n    r => r?,\n}","preventionTips":["Mark go.mod merges carefully; run `go mod tidy` after any merge touching go.mod","Add a pre-commit lint asserting a single module directive","Never concatenate go.mod files from branches by hand"],"tags":["go","gomod","parse-error","duplicate"],"backgroundTag":"schema-validation-failed","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}