Skip to content

library: include path and reason in ReadError/WriteError messages#6645

Open
eyupcanakman wants to merge 1 commit into
beetbox:masterfrom
eyupcanakman:fix/file-error-str-super-6560
Open

library: include path and reason in ReadError/WriteError messages#6645
eyupcanakman wants to merge 1 commit into
beetbox:masterfrom
eyupcanakman:fix/file-error-str-super-6560

Conversation

@eyupcanakman
Copy link
Copy Markdown
Contributor

Description

ReadError.__str__ and WriteError.__str__ put super() straight into an f-string, so a failed read or write printed error reading <super: <class 'ReadError'>, <ReadError object>> and the actual path and reason were lost. Calling super().__str__() returns the FileOperationError message with the path and underlying reason. The reported beet import case now logs the file path and the failure reason.

Fixes #6560.

To Do

  • Documentation
  • Changelog
  • Tests

Copilot AI review requested due to automatic review settings May 16, 2026 20:15
@eyupcanakman eyupcanakman requested a review from a team as a code owner May 16, 2026 20:15
Copy link
Copy Markdown
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

PR fix bug where ReadError.__str__ / WriteError.__str__ print <super: ...> instead of real message. Now error string show file path plus underlying reason, so user can debug read/write fail.

Changes:

  • Fix ReadError and WriteError string formatting to call parent __str__() and include path + reason.
  • Add regression tests to make sure error message no longer contains super: and does include underlying reason.
  • Add changelog entry for bug fix.

Reviewed changes

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

File Description
beets/library/exceptions.py Make ReadError / WriteError use super().__str__() so message includes path + reason.
test/test_library.py Add assertions/tests that error strings no longer show <super: ...> and include reason text.
docs/changelog.rst Document fix in Unreleased bug fixes section.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.45%. Comparing base (fc9c02a) to head (64d6fc1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6645   +/-   ##
=======================================
  Coverage   72.44%   72.45%           
=======================================
  Files         160      160           
  Lines       20690    20690           
  Branches     3272     3272           
=======================================
+ Hits        14989    14991    +2     
+ Misses       4976     4974    -2     
  Partials      725      725           
Files with missing lines Coverage Δ
beets/library/exceptions.py 100.00% <100.00%> (+14.28%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eyupcanakman eyupcanakman force-pushed the fix/file-error-str-super-6560 branch from 24a8e61 to 5826ce5 Compare May 16, 2026 20:23
ReadError and WriteError stringified the super() proxy in their
f-string, so file read and write failures lost the path and reason.
Use super().__str__() to return the FileOperationError message.
@eyupcanakman eyupcanakman force-pushed the fix/file-error-str-super-6560 branch from 5826ce5 to 64d6fc1 Compare May 19, 2026 10:59

def __str__(self):
return f"error reading {super()}"
return f"error reading {super().__str__()}"
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.

Hm I thought enclosing something within {} in a f-string calls __str__ method automatically. If not, I think calling str(super()) is a bit cleaner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right for a normal object, but super() returns a proxy and the f-string (or str()) resolves __str__ on the proxy itself, so {super()} and str(super()) both print <super: ...>. Happy to switch it to FileOperationError.__str__(self) if that reads cleaner, that one forwards to the parent correctly.

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.

I see. It's fine - just add a comment to explain what's going on here, thanks!

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.

ReadError reason not printed

3 participants