Badfiles: 'utf-8' codec can't decode byte on import
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 31
Description
### Problem
Importing with the following config a file where the path contains unicode characters:
```
badfiles:
check_on_import: yes
```
```sh
$> beet imp -m 'A unicode Ǝ string ñ'
```
Led to this problem:
```
Traceback (most recent call last):
File ".local/bin/beet", line 8, in
sys.exit(main())
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/ui/__init__.py", line 1865, in main
_raw_main(args)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/ui/__init__.py", line 1852, in _raw_main
subcommand.func(lib, suboptions, subargs)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/ui/commands.py", line 1395, in import_func
import_files(lib, paths, query)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/ui/commands.py", line 1326, in import_files
session.run()
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/importer.py", line 360, in run
pl.run_parallel(QUEUE_SIZE)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/util/pipeline.py", line 447, in run_parallel
raise exc_info[1].with_traceback(exc_info[2])
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/util/pipeline.py", line 312, in run
out = self.coro.send(msg)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/util/pipeline.py", line 195, in coro
func(*(args + (task,)))
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/importer.py", line 1490, in lookup_candidates
plugins.send("import_task_start", session=session, task=task)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/plugins.py", line 507, in send
result = handler(**arguments)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beets/plugins.py", line 143, in wrapper
return func(*args, **kwargs)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beetsplug/badfiles.py", line 175, in on_import_task_start
error_lines = self.check_item(item)
File ".local/share/pipx/venvs/beets/lib/python3.10/site-packages/beetsplug/badfiles.py", line 128, in check_item
path = item.path.decode(sys.getfilesystemencoding())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 86: invalid continuation byte
```
### Setup
* OS: Ubuntu 24.04
* Python version: 3.10
* beets version: 2.0.0
It seems a similar issue than: https://github.com/beetbox/beets/issues/2168
Contributor guide
Research direction
Reproduce the failure with the shown `beet imp -m` command and `badfiles.check_on_import` enabled. Inspect `beetsplug/badfiles.py`, especially `check_item` where `item.path` is decoded. Done means importing a file whose path contains Unicode characters no longer raises this `UnicodeDecodeError`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100