jdx/mise · error

Go module metadata contains multiple module directives

Error message

Go module metadata contains multiple module directives

What it means

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.

Solutions

  1. Delete the duplicate `module` directive so exactly one remains at the top of go.mod.
  2. 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`.
  3. Run `go mod tidy` afterwards to normalize the file.

Example fix

// before (go.mod)
module example.com/old
module example.com/new

// after
module example.com/new
Defensive patterns

Strategy: validation

Validate before calling

// shell
[ "$(grep -cE '^module[ \t]' go.mod)" -eq 1 ] || { echo "go.mod must have exactly one module directive"; exit 1; }

Try / catch

match read_result {
    Err(e) if e.to_string().contains("multiple module directives") => {
        eprintln!("go.mod corrupted (likely merge); run `git checkout --merge go.mod` or fix manually");
    }
    r => r?,
}

Prevention

When it happens

Trigger: 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.

Common situations: Unresolved git merge conflict in go.mod; copy-pasting a module line from another go.mod; code generators rewriting go.mod incorrectly.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/7664b7ef1f961ce3. Report an issue: GitHub.

Appendix: source

Thrown at src/task/workspace/go.rs:164

    }
    Ok(directories)
}

fn read_module_path(context: &WorkspaceDiscoveryContext, path: &Path) -> Result<String> {
    let contents = context
        .read_to_string(path)
        .wrap_err_with(|| format!("failed to read Go module metadata {}", path.display()))?;
    let mut module_path = None;

    for (index, raw_line) in contents.lines().enumerate() {
        let line = strip_comment(raw_line).trim();
        let Some(arguments) = directive_arguments(line, "module") else {
            continue;
        };
        let parsed = parse_argument(arguments)
            .wrap_err_with(|| format!("invalid module directive on line {}", index + 1))?;
        if module_path.replace(parsed).is_some() {
            bail!("Go module metadata contains multiple module directives");
        }
    }

    module_path.ok_or_else(|| eyre::eyre!("Go module metadata is missing a module directive"))
}

fn directive_arguments<'a>(line: &'a str, directive: &str) -> Option<&'a str> {
    let rest = line.strip_prefix(directive)?;
    if !rest.starts_with(char::is_whitespace) {
        return None;
    }
    Some(rest.trim())
}

fn parse_argument(value: &str) -> Result<String> {
    if value.is_empty() {
        bail!("directive requires one argument");
    }

View on GitHub (pinned to 533346cc37)