Skip to content

Conversation

@sfc-gh-lwilby
Copy link
Collaborator

Describe your changes

Fixes #12868

Updates the error message for invalid width and height values to say "a positive integer" instead of "an integer". This makes the error message more accurate since 0 and negative values are not valid.

Before:

Invalid width value: 0. Width must be either an integer (pixels), 'stretch', or 'content'.

After:

Invalid width value: 0. Width must be either a positive integer (pixels), 'stretch', or 'content'.

Changes

  • Updated StreamlitInvalidWidthError in errors.py to say "a positive integer (pixels)"
  • Updated StreamlitInvalidHeightError in errors.py to say "a positive integer (pixels)"
  • Updated StreamlitInvalidSizeError in errors.py to say "a positive integer (pixels)"
  • Updated all corresponding unit tests to use substring matching for error messages

GitHub Issue Link (if applicable)

Closes #12868

Testing Plan

  • Unit Tests (Python): Updated existing tests in 14 test files to verify the new error message wording. Tests use substring matching (in) to check for the key part of the error message.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-lwilby sfc-gh-lwilby added change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Dec 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13206/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13206.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-lwilby sfc-gh-lwilby added the security-assessment-completed Security assessment has been completed for PR label Dec 3, 2025
@snyk-io
Copy link
Contributor

snyk-io bot commented Dec 3, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@sfc-gh-lwilby sfc-gh-lwilby marked this pull request as ready for review December 3, 2025 16:41
Copilot AI review requested due to automatic review settings December 3, 2025 16:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves error message accuracy by updating width/height validation error messages to specify "a positive integer" instead of "an integer", making it clearer that 0 and negative values are not valid.

Key Changes:

  • Updated error messages in StreamlitInvalidWidthError, StreamlitInvalidHeightError, and StreamlitInvalidSizeError classes
  • Modified 14 test files to use substring matching (in) instead of exact string matching for error message validation

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/streamlit/errors.py Updated error message text in three exception classes to say "a positive integer (pixels)" instead of "an integer (pixels)"
lib/tests/streamlit/spinner_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/text_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/radio_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/pyplot_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/metric_test.py Updated test assertions for both height and width validation to use substring matching
lib/tests/streamlit/elements/markdown_test.py Updated test assertions for markdown, caption, and badge functions to use substring matching
lib/tests/streamlit/elements/image_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/html_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/heading_test.py Updated test assertions for header, subheader, and title functions to use substring matching
lib/tests/streamlit/elements/color_picker_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/checkbox_test.py Updated test assertions for both checkbox and toggle functions to use substring matching
lib/tests/streamlit/elements/button_group_test.py Updated test assertions to use substring matching and updated expected error message text
lib/tests/streamlit/elements/alert_test.py Updated test assertions to use substring matching with proper multi-line formatting

Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@sfc-gh-lwilby sfc-gh-lwilby merged commit 7786739 into develop Dec 3, 2025
57 of 60 checks passed
@sfc-gh-lwilby sfc-gh-lwilby deleted the fix/width-error-message-positive-integer branch December 3, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect error message for width

3 participants