{"record":{"id":"a5be3660307a41e6","repo":"jdx/mise","slug":"unterminated-use-block","errorCode":null,"errorMessage":"unterminated use block","messagePattern":"unterminated use block","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/task/workspace/go.rs","lineNumber":145,"sourceCode":"                format!(\"invalid use directive on line {line_number}\")\n            })?));\n            continue;\n        }\n\n        let Some(arguments) = directive_arguments(line, \"use\") else {\n            continue;\n        };\n        if arguments == \"(\" {\n            in_use_block = true;\n        } else {\n            directories.push(PathBuf::from(parse_argument(arguments).wrap_err_with(\n                || format!(\"invalid use directive on line {line_number}\"),\n            )?));\n        }\n    }\n\n    if in_use_block {\n        bail!(\"unterminated use block\");\n    }\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() {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/task/workspace/go.rs#L127-L163","documentation":"mise's go.work parser tracks block state: after a `use (` line it reads one directory per line until a lone `)`. If the file ends while still inside a `use (` block, parsing fails with 'unterminated use block'. This guards against a truncated or malformed go.work silently yielding a partial module list.","triggerScenarios":"A go.work file contains `use (` but no closing `)` line — e.g. the file was truncated by a failed write, an editor removed the closing paren, or a merge conflict dropped the last lines.","commonSituations":"Botched git merge or rebase of go.work; manually editing go.work and forgetting `)`; generated go.work written incompletely after a crash.","solutions":["Add the closing `)` on its own line after the last `use` entry.","Regenerate go.work with `go work init` plus `go work use ./...` to get a syntactically valid file.","Check for merge-conflict markers and resolve them; commit a complete go.work."],"exampleFix":"// before (go.work)\ngo 1.22\nuse (\n  ./a\n  ./b\n\n// after\ngo 1.22\nuse (\n  ./a\n  ./b\n)","handlingStrategy":"validation","validationCode":"// shell: fail fast on unterminated use blocks\nawk '/^use[ \\t]*\\(/{open=1} /^\\)[ \\t]*$/{open=0} END{exit open?1:0}' go.work \\\n  || { echo \"unterminated use block in go.work\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match parse_result {\n    Err(e) if e.to_string().contains(\"unterminated use block\") => {\n        eprintln!(\"go.work is truncated/malformed; regenerate with `go work use -r .`\");\n    }\n    r => r?,\n}","preventionTips":["After editing go.work, run `gofmt`-adjacent check: `go work sync` parses the file and fails loudly","Resolve go.work merge conflicts completely; never commit conflict markers or partial blocks","Prefer `go work use ./x` CLI edits over manual paren management"],"tags":["go","workspace","parse-error","gomod"],"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"}