{"record":{"id":"d93588106bf8a7c8","repo":"rust-lang/rust","slug":"config-key-not-in-sections-or-top-level-keys","errorCode":null,"errorMessage":"config key {} not in sections or top_level_keys","messagePattern":"config key (.+?) not in sections or top_level_keys","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/bootstrap/configure.py","lineNumber":738,"sourceCode":"                raise RuntimeError(\"failed to find config line for {}\".format(key))\n\n\ndef configure_top_level_key(lines, top_level_key, value):\n    for i, line in enumerate(lines):\n        if line.startswith(\"#\" + top_level_key + \" = \") or line.startswith(\n            top_level_key + \" = \"\n        ):\n            lines[i] = \"{} = {}\".format(top_level_key, to_toml(value))\n            return\n\n    raise RuntimeError(\"failed to find config line for {}\".format(top_level_key))\n\n\n# Modify `sections` to reflect the parsed arguments and example configs.\ndef configure_file(sections, top_level_keys, targets, config):\n    for section_key, section_config in config.items():\n        if section_key not in sections and section_key not in top_level_keys:\n            raise RuntimeError(\n                \"config key {} not in sections or top_level_keys\".format(section_key)\n            )\n        if section_key in top_level_keys:\n            configure_top_level_key(sections[None], section_key, section_config)\n\n        elif section_key == \"target\":\n            for target in section_config:\n                configure_section(targets[target], section_config[target])\n        else:\n            configure_section(sections[section_key], section_config)\n\n\ndef write_uncommented(target, f):\n    \"\"\"Writes each block in 'target' that is not composed entirely of comments to 'f'.\n\n    A block is a sequence of non-empty lines separated by empty lines.\n    \"\"\"\n    block = []","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/bootstrap/configure.py#L720-L756","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Before calling configure_file, validate all section keys\ndef validate_config_keys(config, sections, top_level_keys):\n    for section_key in config:\n        if section_key not in sections and section_key not in top_level_keys:\n            print(f'Unknown config key: {section_key}')\n            print(f'Valid sections: {list(sections.keys())}')\n            print(f'Valid top-level keys: {list(top_level_keys)}')\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    configure_file(sections, top_level_keys, targets, config)\nexcept RuntimeError as e:\n    if 'not in sections or top_level_keys' in str(e):\n        key = str(e).split('key ')[1].split(' not')[0]\n        print(f'Section key \"{key}\" is not a recognized section or top-level key.')\n        print(f'Valid sections: {list(sections.keys())}')\n    raise","preventionTips":["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."],"tags":["bootstrap","rustc","configure","config","validation","python"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}