{"record":{"id":"c575e51ec6c69b7c","repo":"bazelbuild/bazel","slug":"invocation-failed-stderr","errorCode":null,"errorMessage":"invocation failed: {stderr}","messagePattern":"invocation failed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/ctexplain/lib.py","lineNumber":40,"sourceCode":"                  build_flags: Tuple[str, ...]) -> Tuple[ConfiguredTarget, ...]:\n  \"\"\"Gets a build invocation's configured targets.\n\n  Args:\n    bazel: API for invoking Bazel.\n    labels: The targets to build.\n    build_flags: The build flags to use.\n\n  Returns:\n    Configured targets representing the build.\n\n  Raises:\n    RuntimeError: On any invocation errors.\n  \"\"\"\n  cquery_args = [f'deps({\",\".join(labels)})']\n  cquery_args.extend(build_flags)\n  (success, stderr, cts) = bazel.cquery(cquery_args)\n  if not success:\n    raise RuntimeError(\"invocation failed: \" + stderr.decode(\"utf-8\"))\n\n  # We have to do separate calls to \"bazel config\" to get the actual configs\n  # from their hashes.\n  hashes_to_configs = {}\n  cts_with_configs = []\n  for ct in cts:\n    # Don't use dict.setdefault because that unconditionally calls get_config\n    # as one of its parameters and that's an expensive operation to waste.\n    if ct.config_hash not in hashes_to_configs:\n      hashes_to_configs[ct.config_hash] = bazel.get_config(ct.config_hash)\n    config = hashes_to_configs[ct.config_hash]\n    cts_with_configs.append(\n        ConfiguredTarget(ct.label, config, ct.config_hash,\n                         ct.transitive_fragments))\n\n  return tuple(cts_with_configs)\n","sourceCodeStart":22,"sourceCodeEnd":57,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/tools/ctexplain/lib.py#L22-L57","documentation":"Top-level failure in ctexplain's lib: it assembles a cquery command 'deps(<labels>)' plus build flags, runs it through the bazel API, and if the invocation reports failure it raises RuntimeError('invocation failed: ' + decoded stderr). Everything that makes bazel cquery fail surfaces here.","triggerScenarios":"ctexplain run with labels that do not exist, build flags that bazel rejects, a broken workspace (unresolved deps), or a bazel server error — cquery returns non-zero and this error propagates the stderr.","commonSituations":"Typos in labels passed to ctexplain; incompatible flags between the ctexplain invocation and the workspace's .bazelrc; workspace needing a fetch or having conflicting repository rules.","solutions":["Read the appended stderr — it is bazel's own error (unknown label, bad flag, missing repo) and names the real cause.","Fix the labels/flags ctexplain was given; verify them with a manual 'bazel cquery deps(//your:target)'.","Resolve any workspace issues the stderr reports (bazel sync / fetch) and rerun ctexplain."],"exampleFix":"# before\nexplain(['//pkg:nonexistent_target'], [])\n\n# after\nexplain(['//pkg:real_target'], [])  # verify with: bazel cquery 'deps(//pkg:real_target)'","handlingStrategy":"try-catch","validationCode":"rc, out, err = run_bazel(['cquery', 'deps(%s)' % ','.join(labels)] + build_flags)\nif rc != 0:\n    fail_fast('cquery failed; fix labels/flags first: %s' % err)","typeGuard":null,"tryCatchPattern":"try:\n    cts = get_cts(bazel, labels, flags)\nexcept RuntimeError as e:\n    # 'invocation failed: ...' — stderr of bazel is embedded; fix and rerun\n    raise","preventionTips":["Smoke-test the exact cquery command manually before feeding ctexplain.","Keep flags compatible with the workspace's .bazelrc (avoid duplicated/conflicting options)."],"tags":["ctexplain","cquery","bazel","cli"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}