Repository: oumi-ai/oumi
File: src/oumi/cli/cli_utils.py (Python)

Code before:
        raise
    except yaml.YAMLError:
        logger.error("Invalid YAML configuration")
        raise

    return Path(local_path)


def create_github_issue_url(exception: Exception, traceback_str: str) -> str:
    """Create a prefilled GitHub issue URL aligned with the bug report template.

    Args:
        exception: The exception that occurred
        traceback_str: The full traceback string

    Returns:
        str: URL for creating a prefilled GitHub issue
    """
    python_version = (
        f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
    )
    system_info = f"{platform.system()} {platform.release()}"

    # Truncate long error messages and tracebacks to avoid URL length limits
    # URL Length Limit: 2000 characters to be safe in all browsers
    error_msg = (
        str(exception)[:200] + "..." if len(str(exception)) > 200 else str(exception)
    )
    short_traceback = traceback_str.split("\n")[-10:]  # Last 10 lines only
    short_traceback = (
        "\n".join(short_traceback)[:800] + "..."
        if len("\n".join(short_traceback)) > 800
        else "\n".join(short_traceback)
    )

    title = f"[CLI Error]: {type(exception).__name__}"

    command_str = " ".join(sys.argv)
    command_display = f"`{command_str[:100]}{'...' if len(command_str) > 100 else ''}`"

    what_happened = error_msg

    reproduction_steps = (
        f"Steps to reproduce:\n\n"
        f"1. Run command: {command_display}\n\n"
        f"Error message:\n{error_msg}\n\n"
        f"Stack trace:\n```\n{short_traceback}\n```"
    )

    oumi_version = importlib.metadata.version("oumi")
    system_info_content = (

Review comment (suggestion):
nit: if we know the absolute url length limit is 2k, we can use a counter to maximize the amount of text we show in each section without going over the limit. For example:
```
num_chars = 1900 # should be less than 2k to account for chars we have by default
command_display = ...
num_chars -= len(command_display)
error_msg = ...
num_chars -= len(error_msg)
# you can then include as much of the traceback as you can fit in the remaining number of characters, not just limited to 10 lines.
```

Code after:
        raise
    except yaml.YAMLError:
        logger.error("Invalid YAML configuration")
        raise

    return Path(local_path)


def create_github_issue_url(exception: Exception, traceback_str: str) -> str:
    """Create a prefilled GitHub issue URL aligned with the bug report template.

    Args:
        exception: The exception that occurred
        traceback_str: The full traceback string

    Returns:
        str: URL for creating a prefilled GitHub issue
    """
    # 2000 is the max length of a URL to ensure it works with any browser
    MAX_URL_LENGTH = 2000
    base_url = "https://github.com/oumi-ai/oumi/issues/new?"

    python_version = (
        f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
    )
    system_info = f"{platform.system()} {platform.release()}"
    oumi_version = importlib.metadata.version("oumi")
    system_info_content = (
        f"**Please paste the output of `oumi env` here.** "
        f"If you can't run this command, here's basic system info:\n\n"
        f"- Operating system: {system_info}\n"
        f"- Python version: {python_version}\n"
        f"- Oumi version: {oumi_version}"
    )

    title_template = "[Automatic Error Report]: {error_msg}"
    reproduction_template = (
        "Steps to reproduce:\n\n"
        "Command executed: `{command}`\n\n"
        "Stack trace:\n```\n{traceback}\n```"
    )

    exception_str = str(exception)
    command_str = " ".join(sys.argv)

    # Limit the title to 50 chars (unencoded)
    title_error = exception_str[:50]

    command_part = command_str
    error_part = exception_str
    stack_part = traceback_str or ""