Skip to content

fix: raise ValueError with context on malformed signed URL#485

Open
tempoo04 wants to merge 1 commit into
roboflow:mainfrom
tempoo04:fix/signed-url-parse-error-handling
Open

fix: raise ValueError with context on malformed signed URL#485
tempoo04 wants to merge 1 commit into
roboflow:mainfrom
tempoo04:fix/signed-url-parse-error-handling

Conversation

@tempoo04
Copy link
Copy Markdown

What does this PR do?

Fixes a brittle URL parsing pattern in InferenceModel.predict_video() where splitting the signed URL to extract the
expiry value would raise a bare IndexError with no context if the URL format ever changes or is unexpected.

Before:

signed_url_expires = signed_url.split("&X-Goog-Expires")[1].split("&")[0].strip("=")

After:

try:
    signed_url_expires = signed_url.split("&X-Goog-Expires")[1].split("&")[0].strip("=")
except IndexError as e:
    raise ValueError(f"Could not parse expiry from signed URL: {signed_url}") from e

Related Issue(s): N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Testing

  • I have tested this change locally
  • I have added/updated tests for this change

Test details:
No behavioral change for valid URLs. Verified the error path raises ValueError with a descriptive message instead of a
bare IndexError.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings or errors

Additional Context

A bare IndexError gives no indication of what failed or what the URL looked like. The fix wraps the parse in a
try/except and re-raises as ValueError with the offending URL in the message, making debugging significantly faster.

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.

1 participant