rust-lang/rust · error · RuntimeError
config key {} not in sections or top_level_keys
Error message
config key {} not in sections or top_level_keys What it means
Raised by configure_file() in configure.py at line 738. This is a structural validation: when processing parsed config sections, each section_key must be either a known section (in the sections dict, populated from [section] headers in the template) or a known top-level key (in top_level_keys). If a section_key matches neither, the configuration is structurally invalid and cannot be written.
Source
Thrown at src/bootstrap/configure.py:738
raise RuntimeError("failed to find config line for {}".format(key))
def configure_top_level_key(lines, top_level_key, value):
for i, line in enumerate(lines):
if line.startswith("#" + top_level_key + " = ") or line.startswith(
top_level_key + " = "
):
lines[i] = "{} = {}".format(top_level_key, to_toml(value))
return
raise RuntimeError("failed to find config line for {}".format(top_level_key))
# Modify `sections` to reflect the parsed arguments and example configs.
def configure_file(sections, top_level_keys, targets, config):
for section_key, section_config in config.items():
if section_key not in sections and section_key not in top_level_keys:
raise RuntimeError(
"config key {} not in sections or top_level_keys".format(section_key)
)
if section_key in top_level_keys:
configure_top_level_key(sections[None], section_key, section_config)
elif section_key == "target":
for target in section_config:
configure_section(targets[target], section_config[target])
else:
configure_section(sections[section_key], section_config)
def write_uncommented(target, f):
"""Writes each block in 'target' that is not composed entirely of comments to 'f'.
A block is a sequence of non-empty lines separated by empty lines.
"""
block = []View on GitHub (pinned to 7088e4b63a)
Solutions
- List valid section names from the config.toml template: look for [section] headers.
- Check top_level_keys for recognized non-section options.
- Correct the section/key name in the configure invocation.
- If the key is new and valid, add the corresponding [section] header to the template.
Defensive patterns
Strategy: validation
Validate before calling
# Before calling configure_file, validate all section keys
def validate_config_keys(config, sections, top_level_keys):
for section_key in config:
if section_key not in sections and section_key not in top_level_keys:
print(f'Unknown config key: {section_key}')
print(f'Valid sections: {list(sections.keys())}')
print(f'Valid top-level keys: {list(top_level_keys)}')
return False
return True Try / catch
try:
configure_file(sections, top_level_keys, targets, config)
except RuntimeError as e:
if 'not in sections or top_level_keys' in str(e):
key = str(e).split('key ')[1].split(' not')[0]
print(f'Section key "{key}" is not a recognized section or top-level key.')
print(f'Valid sections: {list(sections.keys())}')
raise Prevention
- Cross-check section names against the [section] headers in the config template before configuring.
- Validate top-level keys against the known set.
- Use consistent key naming — typos are the most common cause.
When it happens
Trigger: configure_file(sections, top_level_keys, targets, config) at line 736-740. For each section_key in config.items(): if section_key not in sections AND section_key not in top_level_keys, raise. This fires when the user provides a configuration dict whose top-level key name is neither a recognized TOML section header nor a recognized top-level scalar key.
Common situations: Typo in a section name in the configure arguments (e.g. '--set build.cargo-vs '--set bild.cargo'); using a section name from a different Rust version; passing arbitrary/unknown configuration keys that don't map to any section or top-level key in the current template.
Related errors
- failed to find config line for {}
- src/stage0 doesn't contain a checksum for {}. Pre-built arti
- failed verification
- failed to run: {args}
- no cargo executable found at `{}`
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/d93588106bf8a7c8.
Report an issue: GitHub.