{"record":{"id":"f89d045faf541071","repo":"jdx/mise","slug":"directive-requires-one-argument","errorCode":null,"errorMessage":"directive requires one argument","messagePattern":"directive requires one argument","errorType":"validation","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/task/workspace/go.rs","lineNumber":181,"sourceCode":"        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    }\n    if let Some(value) = value.strip_prefix('\"') {\n        let Some(value) = value.strip_suffix('\"') else {\n            bail!(\"unterminated interpreted Go string\");\n        };\n        return unescape_go_string(value);\n    }\n    if let Some(value) = value.strip_prefix('`') {\n        let Some(value) = value.strip_suffix('`') else {\n            bail!(\"unterminated raw Go string\");\n        };\n        if value.contains('`') {\n            bail!(\"unexpected raw Go string delimiter\");\n        }\n        return Ok(value.to_string());\n    }\n    if value.split_whitespace().count() != 1 {\n        bail!(\"directive requires exactly one argument\");","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/jdx/mise/blob/6f52dcdf99e282ef7a7db68c81301fa4618d0f79/src/task/workspace/go.rs#L163-L199","documentation":"parse_argument, the shared tokenizer for go.work use entries and go.mod module directives, bails when the argument substring handed to it is empty. It is the empty-argument guard at the front of the parser: a directive keyword is present but no path/name token follows it once the line has been comment-stripped and trimmed.","triggerScenarios":"A `use` or `module` directive whose argument portion is blank after `//` comment stripping and trimming (e.g. a line reduced to the keyword plus separating whitespace by an aggressive edit); programmatic callers passing a pre-trimmed empty token; inside a `use (...)` block, an entry line that carries no argument token.","commonSituations":"Hand-edits that delete the path but keep the keyword and its whitespace; scripts that rewrite directive arguments to empty strings instead of removing the line; truncated edits during merge conflict resolution.","solutions":["Give the directive its single argument: `use ./api` or `module example.com/pkg`","If the directive is unwanted, delete the whole line rather than emptying it","Prefer `go work edit` / `go mod edit` over manual text surgery"],"exampleFix":"# before (go.work)\nuse \n\n# after\nuse ./api","handlingStrategy":"validation","validationCode":"fn directive_has_argument(line: &str, keyword: &str) -> bool {\n    match line.strip_prefix(keyword) {\n        Some(rest) => !rest.trim().is_empty(),\n        None => true, // not this directive\n    }\n}","typeGuard":"fn all_directives_have_arguments(contents: &str) -> bool {\n    contents.lines().all(|raw| {\n        let line = raw.split(\"//\").next().unwrap_or(\"\").trim();\n        line != \"use\" && line != \"module\"\n    })\n}","tryCatchPattern":"Err(report) if report.to_string().contains(\"directive requires one argument\") => {\n    // locate the bare keyword line via the wrapped context (\"invalid ... directive on line N\") and remove it\n    remove_bare_directive_lines(&mut contents);\n}","preventionTips":["Delete unwanted directive lines outright instead of blanking their argument","Generate go.work/go.mod edits with `go work edit` / `go mod edit`","Fail CI on keyword-only lines in go.work and go.mod"],"tags":["go","go-work","go-mod","parse","syntax"],"backgroundTag":"missing-required-argument","analyzedSha":"6f52dcdf99e282ef7a7db68c81301fa4618d0f79","analyzedAt":"2026-08-22T10:14:23.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}