Skip to content

Fix to_bytes and to_str raising a string instead of an exception - #1220

Open
magic-peach wants to merge 2 commits into
dapr:mainfrom
magic-peach:fix/to-bytes-to-str-raise-string-not-exception
Open

magic-peach wants to merge 2 commits into
dapr:mainfrom
magic-peach:fix/to-bytes-to-str-raise-string-not-exception

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

Description

to_bytes and to_str did raise f'invalid data type {type(data)}', which raises a plain string instead of an exception. Python turns this into an unrelated TypeError: exceptions must derive from BaseException instead of the intended message. Fixed by wrapping the message in TypeError.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: N/A, self-discovered while reviewing this file, no existing issue filed.

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
@magic-peach
magic-peach requested review from a team as code owners September 18, 2026 09:46

@CasperGN CasperGN left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved.

raise f'invalid data type {type(data)}' raises a string, so Python replaces it with TypeError: exceptions must derive from BaseException and the intended message never reaches the caller. Wrapping it in TypeError is correct, and both to_bytes and to_str are covered by the new tests.

@sicoyle sicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

amazing - thanks!!

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.89%. Comparing base (fb2cd88) to head (30ccb83).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1220   +/-   ##
=======================================
  Coverage   85.89%   85.89%           
=======================================
  Files         163      163           
  Lines       12805    12805           
=======================================
  Hits        10999    10999           
  Misses       1806     1806           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sicoyle sicoyle added the automerge allows dapr bot to merge a PR after tests pass label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge allows dapr bot to merge a PR after tests pass backport release-1.19

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants