Skip to content

Show a one-line error for an invalid CLOUDINARY_URL - #122

Open
TalLevAmi wants to merge 1 commit into
masterfrom
fix/invalid-cloudinary-url-error
Open

TalLevAmi wants to merge 1 commit into
masterfrom
fix/invalid-cloudinary-url-error

Conversation

@TalLevAmi

Copy link
Copy Markdown
Contributor

With an invalid CLOUDINARY_URL (for example CLOUDINARY_URL=garbage), every cld command printed a full Python traceback that ended in ValueError: Invalid CLOUDINARY_URL scheme. The SDK reads the variable when it is imported, so the error occurs before the error handling in main().

Now the output is:

error: Invalid CLOUDINARY_URL scheme. Expecting to start with 'cloudinary://'. Fix or unset the CLOUDINARY_URL environment variable.

Brief Summary of Changes

  • cloudinary_cli/__init__.py catches ValueError from import cloudinary and calls sys.exit with the message. The exit code is 1.
  • The new test runs the CLI in a subprocess, because the error occurs at import time.

What does this PR address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are tests included?

  • Yes
  • No

Reviewer, please note:

  • The CLI still stops when CLOUDINARY_URL is invalid and you select a saved config with -C. This is the same as before, because the SDK cannot be imported with that value.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all the tests pass.

Local test run: I ran the full suite on Python 3.8 with Click 8.1.8. The new tests pass, and they fail without the fix. 8 tests in test_cli_agent.py and test_cli_config_oauth.py fail with stderr not separately captured on this branch and on master too. These tests need Click 8.2, which needs Python 3.10 or later. CI must confirm the full result.

🤖 Generated with Claude Code

With `CLOUDINARY_URL=garbage`, every command printed a Python traceback.
The SDK reads the variable when it is imported, before `main()` can
handle errors.

Catch the `ValueError` from `import cloudinary` and exit with one line
that tells the user to fix or unset the variable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TalLevAmi
TalLevAmi marked this pull request as ready for review September 26, 2026 16:15

@const-cloudinary const-cloudinary left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TalLevAmi , this is a nice bug.
Unfortunately, the fix is not quite complete.
We have a few ways to configure CLI, using cld -C or cld -c. They take precedence over ENV variable, so we should not crash in this case, even if ENV variable is broken.
And this PR does not address CLOUDINARY_ACCOUNT_URL, which produces similar error.

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.

2 participants