jdx/mise · error
unterminated use block
Error message
unterminated use block
What it means
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.
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.
Example fix
// before (go.work) go 1.22 use ( ./a ./b // after go 1.22 use ( ./a ./b )
Defensive patterns
Strategy: validation
Validate before calling
// shell: fail fast on unterminated use blocks
awk '/^use[ \t]*\(/{open=1} /^\)[ \t]*$/{open=0} END{exit open?1:0}' go.work \
|| { echo "unterminated use block in go.work"; exit 1; } Try / catch
match parse_result {
Err(e) if e.to_string().contains("unterminated use block") => {
eprintln!("go.work is truncated/malformed; regenerate with `go work use -r .`");
}
r => r?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Botched git merge or rebase of go.work; manually editing go.work and forgetting `)`; generated go.work written incompletely after a crash.
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
- Go module metadata contains multiple module directives
- directive requires exactly one argument
- directive requires one argument
- Go workspace module is missing
- Go workspace module is missing go.mod
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/a5be3660307a41e6.
Report an issue: GitHub.
Appendix: source
Thrown at src/task/workspace/go.rs:145
format!("invalid use directive on line {line_number}")
})?));
continue;
}
let Some(arguments) = directive_arguments(line, "use") else {
continue;
};
if arguments == "(" {
in_use_block = true;
} else {
directories.push(PathBuf::from(parse_argument(arguments).wrap_err_with(
|| format!("invalid use directive on line {line_number}"),
)?));
}
}
if in_use_block {
bail!("unterminated use block");
}
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() {View on GitHub (pinned to 533346cc37)