or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/tox-pyenv@1.1.x
tile.json

tessl/pypi-tox-pyenv

tessl install tessl/pypi-tox-pyenv@1.1.0

tox plugin that makes tox use `pyenv which` to find python executables

Agent Success

Agent success rate when using this tile

98%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.03x

Baseline

Agent success rate without this tile

95%

task.mdevals/scenario-9/

Process Runner with Custom Exceptions

Build a simple process execution wrapper that uses a custom exception hierarchy to handle different types of process execution failures.

Requirements

Your task is to implement a process runner module that executes system commands and handles errors using a well-structured exception hierarchy.

Exception Hierarchy

Design and implement a custom exception hierarchy with:

  1. A base exception class for all process-related errors
  2. A specific exception class for when the requested executable is not found on the system
  3. A specific exception class for when the executable is found but returns a non-zero exit code
  4. All exceptions should capture and preserve error context (such as stderr output) to aid in debugging

The hierarchy should follow Python exception best practices where more specific exceptions inherit from more general ones.

Core Functionality

Implement a function that executes system commands with the following behavior:

  • Accepts a command name and optional arguments
  • Attempts to locate and execute the command as a subprocess
  • Returns the stdout output if the command succeeds (exit code 0)
  • Raises the appropriate custom exception type for different failure scenarios
  • Includes relevant error details in exceptions (such as stderr output and exit codes)

Test Cases

  • When the executable does not exist on the system, the appropriate custom exception is raised @test
  • When the executable exists but exits with a non-zero status, the appropriate custom exception is raised @test
  • When the executable succeeds with exit code 0, stdout is returned with whitespace trimmed @test
  • All custom exceptions are subclasses of the base exception class @test

Implementation

@generates

API

class ProcessException(Exception):
    """Base exception for process execution errors."""
    pass

class ExecutableNotFound(ProcessException):
    """Raised when the requested executable cannot be found."""
    pass

class ExecutionFailed(ProcessException):
    """Raised when the executable runs but exits with non-zero status."""
    pass

def run_command(executable, *args):
    """
    Execute a system command and return its output.

    Args:
        executable: The command/executable name to run
        *args: Optional arguments to pass to the command

    Returns:
        str: The stdout output from the command (stripped)

    Raises:
        ExecutableNotFound: If the executable cannot be found
        ExecutionFailed: If the executable exits with non-zero status
    """
    pass

Dependencies { .dependencies }

This implementation should use only Python standard library modules.