{"id":"a84a8bf7d624887a","repo":"apache/kafka","slug":"failure-in-executing-following-command","errorCode":null,"errorMessage":"Failure in executing following command:- ","messagePattern":"Failure in executing following command:- ","errorType":"exception","errorClass":"SystemError","httpStatus":null,"severity":"error","filePath":"docker/common.py","lineNumber":25,"sourceCode":"# (the \"License\"); you may not use this file except in compliance with\n# the License.  You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport subprocess\nimport tempfile\nimport os\nimport shutil\n\ndef execute(command):\n    if subprocess.run(command).returncode != 0:\n        raise SystemError(\"Failure in executing following command:- \", \" \".join(command))\n\ndef get_input(message):\n    value = input(message)\n    if value == \"\":\n        raise ValueError(\"This field cannot be empty\")\n    return value\n\ndef build_docker_image_runner(command, image_type, kafka_archive=None):\n    temp_dir_path = tempfile.mkdtemp()\n    current_dir = os.path.dirname(os.path.realpath(__file__))\n    shutil.copytree(f\"{current_dir}/{image_type}\", f\"{temp_dir_path}/{image_type}\", dirs_exist_ok=True)\n    shutil.copytree(f\"{current_dir}/resources\", f\"{temp_dir_path}/{image_type}/resources\", dirs_exist_ok=True)\n    shutil.copy(f\"{current_dir}/server.properties\", f\"{temp_dir_path}/{image_type}\")\n    if kafka_archive:\n        shutil.copy(kafka_archive, f\"{temp_dir_path}/{image_type}/kafka.tgz\")\n    command = command.replace(\"$DOCKER_FILE\", f\"{temp_dir_path}/{image_type}/Dockerfile\")\n    command = command.replace(\"$DOCKER_DIR\", f\"{temp_dir_path}/{image_type}\")\n    try:","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/docker/common.py#L7-L43","documentation":"Raised by docker/common.execute() when subprocess.run(command) returns a non-zero exit code. execute() is the shared wrapper used by build_docker_image_runner, docker_release, and related scripts to run shell commands (docker build, docker buildx create/rm, etc.). The message echoes the joined command so the failing invocation is identifiable, though the original stderr is lost.","triggerScenarios":"Any call to execute(cmd) where cmd is a list passed to subprocess.run and the spawned process exits non-zero. In this repo that means docker buildx create (line 54 of docker_release.py), docker buildx rm (line 57), or the inner execute() inside build_docker_image_runner (common.py:44).","commonSituations":"docker buildx not installed or not enabled, docker daemon not running, builder name 'kafka-builder' already exists (on create) or already removed (on rm), network/proxy issues pulling base images, disk full, or a malformed Dockerfile/build context path.","solutions":["Re-run the exact command shown in the error message manually to see docker's stderr, which execute() discards.","Ensure docker is installed, running, and docker buildx is available: docker buildx version.","If the failure is 'kafka-builder already exists', run docker buildx rm kafka-builder first; if 'not found', ignore or guard remove_builder().","Verify prerequisites from docker_release.py docstring: logged in to registry, buildx enabled, adequate disk."],"exampleFix":"# before (execute swallows stderr)\nsubprocess.run(command).returncode != 0  # you see only the command\n# after (capture and surface stderr)\nresult = subprocess.run(command, capture_output=True, text=True)\nif result.returncode != 0:\n    raise SystemError(f\"Failure executing {command}: {result.stderr}\")","handlingStrategy":"try-catch","validationCode":"# Validate the command is well-formed and the binary is on PATH before running.\nimport shutil, shlex\nbinary = command.split()[0] if isinstance(command, str) else command[0]\nif not shutil.which(binary):\n    raise FileNotFoundError(f\"Executable not found on PATH: {binary}\")","typeGuard":"# Accept only a non-empty, shell-safe command list.\ndef is_executable_command(cmd) -> bool:\n    if not cmd:\n        return False\n    parts = cmd if isinstance(cmd, list) else shlex.split(cmd)\n    return len(parts) > 0 and bool(shutil.which(parts[0]))","tryCatchPattern":"from common import execute\ntry:\n    execute(command)\nexcept SystemError as e:\n    # Inspect the captured command; retry only transient failures, not bad input.\n    failed_cmd = e.args[1] if len(e.args) > 1 else \"<unknown>\"\n    raise RuntimeError(f\"Command failed, inspect manually: {failed_cmd}\") from e","preventionTips":["Always run docker/gradle/git commands through execute() and surface SystemExit rather than ignoring return codes.","Validate the command string (non-empty, binary resolvable on PATH) before calling execute().","Log the exact command and its stderr so a failure is reproducible; avoid bare 'except:' that hides the root cause.","For commands that touch the network (docker pull, gradle download), consider a bounded retry with exponential backoff."],"tags":["python","docker","subprocess","buildx","release-tooling"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}