jdx/mise · error

directive requires one argument

Error message

directive requires one argument

What it means

parse_argument parses the argument of a Go directive (module, use) in go.work/go.mod. An empty argument — nothing after the directive keyword, or only whitespace — cannot name a directory or module path, so it bails with 'directive requires one argument'.

Solutions

  1. Give the directive an argument: `use ./dir` or `module example.com/m`.
  2. Delete the empty directive line entirely.
  3. Wrap multiple entries in a use block properly (`use ( ... )`) instead of repeating a bare `use`.

Example fix

// before (go.work)
use

// after
use ./services/api
Defensive patterns

Strategy: validation

Validate before calling

// shell
awk '$1=="use" && NF<2 && $0 !~ /\($/ && $0 !~ /^use[ \t]*\($/ {print "bare directive: " $0; bad=1} END{exit bad}' go.work

Prevention

When it happens

Trigger: go.work has `use` with no argument, or inside a use block an empty/whitespace-only line survives comment stripping and trimming, then reaches parse_argument; same for a bare `module` line in go.mod.

Common situations: Editing go.work and leaving a dangling `use` line; a commented-out value (`use // ./x`) leaving only the keyword; generated files with blank lines inside a use block (blank lines are skipped, but keyword-only lines are not).

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

        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");
    }
    if let Some(value) = value.strip_prefix('"') {
        let Some(value) = value.strip_suffix('"') else {
            bail!("unterminated interpreted Go string");
        };
        return unescape_go_string(value);
    }
    if let Some(value) = value.strip_prefix('`') {
        let Some(value) = value.strip_suffix('`') else {
            bail!("unterminated raw Go string");
        };
        if value.contains('`') {
            bail!("unexpected raw Go string delimiter");
        }
        return Ok(value.to_string());
    }
    if value.split_whitespace().count() != 1 {
        bail!("directive requires exactly one argument");

View on GitHub (pinned to 533346cc37)