{"record":{"id":"b7a8e1255eb8d92b","repo":"tensorflow/models","slug":"error-executing-command-cmd-error-stderr","errorCode":null,"errorMessage":"Error executing command: {cmd}. Error: {stderr}","messagePattern":"Error executing command: (.+?)\\. Error: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"official/projects/waste_identification_ml/model_inference/download_and_unzip_models.py","lineNumber":67,"sourceCode":"  def __init__(self, cmd, returncode, stderr):\n    super().__init__(f\"Error executing command: {cmd}. Error: {stderr}\")\n    self.cmd = cmd\n    self.returncode = returncode\n    self.stderr = stderr\n\n\ndef execute_command(cmd: str) -> str:\n  \"\"\"Executes a shell command and returns its output.\"\"\"\n  result = subprocess.run(\n      cmd,\n      shell=True,\n      stdout=subprocess.PIPE,\n      stderr=subprocess.PIPE,\n      check=False,\n  )\n\n  if result.returncode != 0:\n    raise CommandExecutionError(\n        cmd, result.returncode, result.stderr.decode(\"utf-8\")\n    )\n\n  return result.stdout.decode(\"utf-8\")\n\n\ndef main(_) -> None:\n  # Download the provided files\n  execute_command(f\"wget {args.material_url}\")\n  execute_command(f\"wget {args.material_form_url}\")\n\n  # Create directories\n  os.makedirs(\"material\", exist_ok=True)\n  os.makedirs(\"material_form\", exist_ok=True)\n\n  # Unzip the provided files\n  zip_file1 = os.path.basename(args.material_url)\n  zip_file2 = os.path.basename(args.material_form_url)","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/waste_identification_ml/model_inference/download_and_unzip_models.py#L49-L85","documentation":"CommandExecutionError raised by execute_command when a subprocess.run call returns a non-zero exit code. The exception enriches the generic failure with cmd, returncode, and decoded stderr so callers (main, driving wget/unzip model downloads) can report exactly which shell command failed and why. It signals that the wrapped tool failed — bad URL, missing binary, disk full, corrupt archive — not a Python-level bug.","triggerScenarios":"Thrown at official/projects/waste_identification_ml/model_inference/download_and_unzip_models.py:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the exception's stderr and returncode fields for the underlying tool's error message","Run the failing cmd manually in a shell to reproduce and diagnose (URL validity, disk space, unzip availability)","Retry transient network failures such as timed-out downloads","Fix command construction (quoting, paths) if stderr shows a usage error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}