Skip to content

fix: handle invalid slug gracefully to prevent CLI crash - #744

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix-invalid-slug-crash
Open

fix: handle invalid slug gracefully to prevent CLI crash#744
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix-invalid-slug-crash

Conversation

@sentry

@sentry sentry Bot commented Jul 27, 2026

Copy link
Copy Markdown

This PR addresses issue CLI-2N, where the Codecov CLI would crash with an unhandled ValueError: The provided slug is invalid when the slug argument was either not provided by the user or could not be auto-detected from the environment.

Root Cause:
The encode_slug function in codecov_cli/helpers/encoder.py raises a ValueError for invalid or None slugs. Previously, this ValueError was not caught by the calling service functions (e.g., create_commit_logic), leading to an unhandled exception and a CLI crash.

Solution:

  1. Introduced a new helper function safe_encode_slug in codecov_cli/helpers/encoder.py. This function wraps encode_slug in a try-except block, logs a user-friendly error message, and returns None if the slug is invalid.
  2. Modified all call sites of encode_slug across various service modules (e.g., commit, report, empty_upload, upload_completion, upload_sender, get_report_results) to use safe_encode_slug.
  3. Added a check after calling safe_encode_slug: if it returns None, a click.UsageError is raised. This ensures the CLI exits cleanly with a clear error message to the user, rather than crashing.

Fixes CLI-2N

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
723 1 722 1
View the full list of 1 ❄️ flaky test(s)
api.temp.calculator.test_calculator::test_divide

Flake rate in main: 100.00% (Passed 0 times, Failed 1625 times)

Stack Traces | 0.001s run time
def
                test_divide():
                > assert Calculator.divide(1, 2) == 0.5
                E assert 1.0 == 0.5
                E + where 1.0 = <function Calculator.divide at 0x104c9eb90>(1, 2)
                E + where <function Calculator.divide at 0x104c9eb90> = Calculator.divide
                .../temp/calculator/test_calculator.py:30: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants