{"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":"exception","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/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/task/workspace/go.rs#L146-L182","documentation":"When reading a Go module file's metadata, mise collects the value of each `module` directive. This error is thrown if more than one `module` line is found, since a Go module must declare exactly one module path. The parser refuses to guess which path is authoritative.","triggerScenarios":"`read_module_path` iterating lines of a go.mod-like file via `directive_arguments(line, \"module\")` and encountering a second `module <path>` line after one was already parsed.","commonSituations":"Duplicated module lines after a bad merge or copy-paste in a go.mod; concatenating two module files; generated tooling appending a module directive without removing the old one.","solutions":["Remove the duplicate `module` line so exactly one remains","If the file is generated, regenerate it from a single canonical source and diff before committing","Check git history to see which module path is correct and delete the other"],"exampleFix":"// before (go.mod)\nmodule example.com/app\nmodule example.com/app/v2\n// after\nmodule example.com/app\n","handlingStrategy":"validation","validationCode":"fn validate_single_module(contents: &str) -> Result<()> {\n    let count = contents.lines().filter(|l| l.trim_start().starts_with(\"module \")).count();\n    anyhow::ensure!(count <= 1, \"expected at most one module directive, found {count}\");\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one `module` line per module file","Check merge results for duplicated directive lines","Regenerate generated module files rather than hand-editing duplicates"],"tags":["go","parsing","config"],"backgroundTag":"schema-validation-failed","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}