beetbox / beets

music library manager and MusicBrainz tagger
http://beets.io/
MIT License
12.58k stars 1.8k forks source link

Extraneous "b" in error messages #5181

Open MarkTerMors opened 3 months ago

MarkTerMors commented 3 months ago

When beets presents an error message there is sometimes an extraneous letter "b" at the start of the path in the message.

Problem

This album is already in the library! V could not get filesize: [Errno 2] No such file or directory: b'/media/music/P/Peter Tosh/Equal Rights/01 Get Up, Stand Up.1.mp3'

Led to this problem:

(paste here)

beets version 1.6.1 Python version 3.11.2

Setup

arsaboo commented 3 months ago

This is likely not an issue with the path itself but how the error message is formatted or how the path is being handled internally by beets. It is probably related to how Python represents byte strings. The "b" prefix indicates that the string is in bytes rather than a standard string (which is in Unicode).

wisp3rwind commented 2 months ago

Looks like this is coming from https://github.com/beetbox/beets/blob/6077b7a3a1037abbf046a00fbbc05db0401982a1/beets/library.py#L958

If we want to pretty-print this, I guess we should be catching the various subclasses of OSError explicity and apply displayable_path when logging them (i.e. manually format the message instead of interpolating "{exc}"). Not sure whether that is worth the effort.