question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

commitizen_emoji cannot write to CHANGELOG

See original GitHub issue

Description

This is because commitizen_emoji uses unicode emoji characters, but commitizen does not specify the file encoding in write_changelog(), so it defaults back to cp1252:

https://github.com/commitizen-tools/commitizen/blob/79165119817cbd0aef25434a85dcbffa3a13acbb/commitizen/commands/changelog.py#L92

This could be fixed by specifying the utf-8 encoding:

with open(self.file_name, "w", encoding='utf-8') as changelog_file: 
   ...

Steps to reproduce

> cz bump --changelog
bump: version 0.4.0 → 0.5.0
tag to create: 0.5.0       
increment detected: MINOR  

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\hendra11\Code\external\cz-emoji\.venv\Scripts\cz.exe\__main__.py", line 7, in <module>
  File "C:\Users\hendra11\Code\external\cz-emoji\.venv\lib\site-packages\commitizen\cli.py", line 382, in main
    args.func(conf, vars(args))()
  File "C:\Users\hendra11\Code\external\cz-emoji\.venv\lib\site-packages\commitizen\commands\bump.py", line 215, in __call__
    changelog_cmd()
  File "C:\Users\hendra11\Code\external\cz-emoji\.venv\lib\site-packages\commitizen\commands\changelog.py", line 172, in __call__
    self.write_changelog(changelog_out, lines, changelog_meta)
  File "C:\Users\hendra11\Code\external\cz-emoji\.venv\lib\site-packages\commitizen\commands\changelog.py", line 103, in write_changelog
    changelog_file.write(changelog_out)
  File "C:\Program Files\Python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f389' in position 29: character maps to <undefined>

Current behavior

See Steps to reproduce

Desired behavior

Emojis can be logged to changelog

Screenshots

No response

Environment

  • cz version: 2.27.0
  • python version: 3.8.13
  • platform.system(): ‘Windows’

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Lee-Wcommented, Oct 17, 2022

It would be even more helpful if you could document this on the doc for windows users. Thanks!

1reaction
adam-grant-hendrycommented, May 22, 2022

‘utf-8’ should cover all encodings, but I’m fine with that. You’d have to change BaseCommitizen to grab that config variable and everywhere you have an open used in your codebase, change it to add the encoding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'version' of undefined #123 - GitHub
json here. Nevertheless, I'd like to use Angular's commit log conventions for all my projects and generate a weekly changelog, say, for the...
Read more >
A Beginner's Guide to Git — What is a Changelog and How to ...
How to generate a changelog (the simple way). By using this first way, you don't need any prerequisites. All you need is to...
Read more >
Automatically generate and release a changelog using Node.js
Use the Conventional Commits format to automatically generate and release a changelog for your project that follows semantic versioning.
Read more >
Changelog entries - GitLab Docs
This guide contains instructions for when and how to generate a changelog entry file, as well as information and history ... Writing good...
Read more >
How To Automatically Generate A Helpful Changelog From ...
Usually, the message does not describe where changes were made, what was changed, and what was the motivation for making the changes. So...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found