Skip to content

Don't crash on non-unicode files #5

@simonw

Description

@simonw

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 10

Got this error running against a folder with a binary in it.

>>> import pdb
>>> pdb.pm()
> /opt/homebrew/Caskroom/miniconda/base/lib/python3.10/codecs.py(322)decode()
-> (result, consumed) = self._buffer_decode(data, self.errors, final)
(Pdb) u
> /Users/simon/.local/pipx/venvs/files-to-prompt/lib/python3.10/site-packages/files_to_prompt/cli.py(66)process_path()
-> file_contents = f.read()
(Pdb) list
 61  	                ]
 62  	
 63  	            for file in files:
 64  	                file_path = os.path.join(root, file)
 65  	                with open(file_path, "r") as f:
 66  ->	                    file_contents = f.read()
 67  	
 68  	                click.echo(file_path)
 69  	                click.echo("---")
 70  	                click.echo(file_contents)
 71  	                click.echo()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions