bazelbuild/bazel · error · ValueError
Could not get config: {stderr}
Error message
Could not get config: {stderr} What it means
Thrown by tools/ctexplain's bazel_api.get_config() when 'bazel config --output=json <hash>' exits non-zero. ctexplain resolves each configuration hash from cquery output into a full Configuration via this call; failure to fetch the config aborts with the raw bazel stderr attached.
Source
Thrown at tools/ctexplain/bazel_api.py:114
Args:
config_hash: A config hash as reported by "bazel cquery".
Returns:
The matching configuration or None if no match is found.
Raises:
ValueError: On any parsing problems.
"""
if config_hash == "HOST":
return HostConfiguration()
elif config_hash == "null":
return NullConfiguration()
base_args = ["config", "--output=json"]
(returncode, stdout, stderr) = self.run_bazel(base_args + [config_hash])
if returncode != 0:
raise ValueError("Could not get config: " + stderr)
config_json = json.loads(os.linesep.join(stdout))
fragments = frozendict({
_base_name(entry["name"]):
tuple(_base_name(clazz) for clazz in entry["fragmentOptions"])
for entry in config_json["fragments"]
})
options = frozendict({
_base_name(entry["name"]): frozendict(entry["options"])
for entry in config_json["fragmentOptions"]
})
return Configuration(fragments, options)
# TODO(gregce): have cquery --output=jsonproto support --show_config_fragments
# so we can replace all this regex parsing with JSON reads.
def _parse_cquery_result_line(line: str) -> ConfiguredTarget:
"""Converts a cquery output line to a ConfiguredTarget.
View on GitHub (pinned to e6e199d060)
Solutions
- Run 'bazel config <hash>' manually with the same output base to see the underlying bazel error shown in stderr.
- Regenerate the cquery data you are diffing in the same workspace state so hashes exist in the current server.
- Restart/shut down the bazel server ('bazel shutdown') if a version or workspace change invalidated it, then retry.
Defensive patterns
Strategy: try-catch
Validate before calling
rc, out, err = run_bazel(['config', '--output=json', config_hash])
if rc != 0:
raise ValueError('config %s unknown to server: %s' % (config_hash, err)) Try / catch
try:
config = bazel.get_config(ct.config_hash)
except ValueError as e:
# 'Could not get config: ...' — regenerate cquery data in this workspace
raise Prevention
- Generate and consume cquery dumps within one bazel server lifetime.
- Pre-check unknown hashes with 'bazel config <hash>' before running ctexplain on old data.
When it happens
Trigger: Passing a config hash that the current bazel server does not know (from a stale cquery dump or a different output base), the bazel server being shut down mid-run, or bazel itself erroring (e.g. workspace problems) during 'bazel config'.
Common situations: Comparing cquery output captured before a 'bazel clean' or server restart; running ctexplain in a workspace where bazel needs a restart (version change); config hash from another invocation directory.
Related errors
- {tokens[1]} in {line} not surrounded by parentheses
- {tokens[2]} in {line} not surrounded by [] brackets
- invocation failed: {stderr}
- Could not create custom sharding strategy class ${strategy}
- Unsupported JUnit Runner API version ${JUNIT_API_VERSION_PRO
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/0d2aaa789770ec92.
Report an issue: GitHub.