tensorflow/models · error · CommandExecutionError

Error executing command

Error message

Error executing command: {cmd}. Error: {stderr}

What it means

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.

Solutions

  1. Inspect the exception's stderr and returncode fields for the underlying tool's error message
  2. Run the failing cmd manually in a shell to reproduce and diagnose (URL validity, disk space, unzip availability)
  3. Retry transient network failures such as timed-out downloads
  4. Fix command construction (quoting, paths) if stderr shows a usage error
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at official/projects/waste_identification_ml/model_inference/download_and_unzip_models.py:67 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/b7a8e1255eb8d92b. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/waste_identification_ml/model_inference/download_and_unzip_models.py:67

  def __init__(self, cmd, returncode, stderr):
    super().__init__(f"Error executing command: {cmd}. Error: {stderr}")
    self.cmd = cmd
    self.returncode = returncode
    self.stderr = stderr


def execute_command(cmd: str) -> str:
  """Executes a shell command and returns its output."""
  result = subprocess.run(
      cmd,
      shell=True,
      stdout=subprocess.PIPE,
      stderr=subprocess.PIPE,
      check=False,
  )

  if result.returncode != 0:
    raise CommandExecutionError(
        cmd, result.returncode, result.stderr.decode("utf-8")
    )

  return result.stdout.decode("utf-8")


def main(_) -> None:
  # Download the provided files
  execute_command(f"wget {args.material_url}")
  execute_command(f"wget {args.material_form_url}")

  # Create directories
  os.makedirs("material", exist_ok=True)
  os.makedirs("material_form", exist_ok=True)

  # Unzip the provided files
  zip_file1 = os.path.basename(args.material_url)
  zip_file2 = os.path.basename(args.material_form_url)

View on GitHub (pinned to e006f5f0d5)