+
Skip to content

fix: Fix unicode error on binary files #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 3, 2021
Merged

fix: Fix unicode error on binary files #436

merged 5 commits into from
Aug 3, 2021

Conversation

pawamoy
Copy link
Contributor

@pawamoy pawamoy commented Aug 1, 2021

If a unicode decode error is raised
while trying to compile a file as a Jinja2 template,
and the templates suffix is empty,
we fallback to copying this file as is.

Fixes #433.

If a unicode decode error is raised
while trying to compile a file as a Jinja2 template,
and the templates suffix is empty,
we fallback to copying this file as is.

Fixes #433.
@pawamoy pawamoy marked this pull request as draft August 1, 2021 13:51
@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2021

Codecov Report

Merging #436 (a975244) into master (2fe3072) will decrease coverage by 0.01%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
- Coverage   96.33%   96.32%   -0.02%     
==========================================
  Files          39       39              
  Lines        2456     2473      +17     
==========================================
+ Hits         2366     2382      +16     
- Misses         90       91       +1     
Flag Coverage Δ
unittests 96.32% <95.23%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
copier/main.py 94.53% <85.71%> (-0.24%) ⬇️
tests/helpers.py 100.00% <100.00%> (ø)
tests/test_empty_suffix.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2fe3072...a975244. Read the comment docs.

Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

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

Almost perfect, thanks 🙂

@pawamoy pawamoy marked this pull request as ready for review August 1, 2021 17:52
@pawamoy
Copy link
Contributor Author

pawamoy commented Aug 3, 2021

Please squash and merge, there's only one real commit, the rest are fixups.

except UnicodeDecodeError:
if self.template.templates_suffix:
# suffix is not emtpy, re-raise
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should raise a UserMessageError then?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's OK as it is. That kind of exception would print a nice human-readable message in the CLI, but in this case I don't think we should hide the stack trace. If you add the .jinja suffix to a binary file, it's a wrong usage of Copier and it should die badly, and the stack trace should tell you what's happening.

Let's see, if too many people open issues about that message not being understood, I think we can add it, but TBH I think it's too much of a corner case.

@yajo yajo merged commit b3860dd into copier-org:master Aug 3, 2021
@yajo yajo added this to the v6.0.0 milestone Mar 7, 2022
@pawamoy pawamoy deleted the fix-unidecode-binary-files branch April 2, 2024 10:43
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.

bug: _templates_suffix: "" gives UnicodeDecodeError on binary files ( .ico or .png for example )
3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载