rust-lang/rust · error · Exception
line {}: {}
Error message
line {}: {} What it means
Raised by get_commands() in htmldocck when shlex.split() on the args portion of a //@ directive throws an exception other than UnicodeEncodeError. The line number (1-based) and the original exception message are embedded so the offending directive in the rustdoc test template can be located. It is a template-authoring error surfaced while parsing the .rs file.
Source
Thrown at src/etc/htmldocck.py:190
line,
"Deprecated command syntax, replace `// @` with `//@ `",
)
continue
m = LINE_PATTERN.search(line)
if not m:
continue
cmd = m.group("cmd")
negated = m.group("negated") == "!"
args = m.group("args") or ""
try:
args = shlex.split(args)
except UnicodeEncodeError:
args = [
arg.decode("utf-8") for arg in shlex.split(args.encode("utf-8"))
]
except Exception as exc:
raise Exception("line {}: {}".format(lineno + 1, exc)) from None
yield Command(
negated=negated, cmd=cmd, args=args, lineno=lineno + 1, context=line
)
def _flatten(node, acc):
if node.text:
acc.append(node.text)
for e in node:
_flatten(e, acc)
if e.tail:
acc.append(e.tail)
def flatten(node):
acc = []
_flatten(node, acc)
return "".join(acc)View on GitHub (pinned to 7088e4b63a)
Solutions
- Open the .rs test file at the reported line and fix the shell syntax of the directive's arguments (balance quotes, remove stray backslashes).
- Use shlex-safe quoting: wrap literal values in matching single or double quotes.
- Re-run the test to confirm the parse error is gone.
Example fix
// before (in the .rs file) //@ has: '//*[@id="foo"]' "bar" // line with mismatched/odd quoting // after //@ has: //*[@id="foo"] bar
Defensive patterns
Strategy: validation
Validate before calling
import shlex
def directive_args_parse_ok(args_str: str):
try:
shlex.split(args_str)
return True, None
except Exception as e:
return False, str(e)
ok, err = directive_args_parse_ok(args_string_from_template)
if not ok:
raise SystemExit(f"directive has invalid shlex syntax: {err}") Type guard
null
Try / catch
try:
commands = list(get_commands(template))
except Exception as e:
if e.args and isinstance(e.args[0], str) and e.args[0].startswith("line "):
lineno_msg = e.args[0]
logging.error("htmldocck template syntax error: %s", lineno_msg)
raise Prevention
- Balance all quotes in //@ directive arguments.
- Avoid stray backslashes in directive lines (use the line-continuation rules of concat_multi_lines instead).
- Lint test templates with shlex.split in a pre-commit hook.
When it happens
Trigger: A //@ directive line whose args string is not valid shell-lex syntax: unbalanced quotes, a stray backslash, an unclosed substitution, etc. Reached at htmldocck.py:189-190 in the generic `except Exception as exc` branch of shlex.split.
Common situations: Editing a rustdoc UI test and adding a directive with an unbalanced quote (e.g. `//@ has: 'foo"`); copy-pasting a directive that contained shell metacharacters; trailing backslash in the args that confuses shlex.
Related errors
- Non-absolute XPath is not supported due to implementation is
- Tried to use the previous path in the first command
- glob path does not resolve to one file
- File does not exist {!r}
- Cannot parse an HTML file {!r}: {}
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/0971493147d2707e.
Report an issue: GitHub.