Skip to content

Exceptions when using cz from ISO8859-1 Terminal #956

Open
@keenonkites

Description

@keenonkites

Description

When issuing 'cz info' from a ISO8859-1 encoded Terminal I get the following exception:

[xx@XXXXXX:~/tmp/test-git-repo (master +)] $ cz info
Traceback (most recent call last):
  File "/home/user/pb/venv_commitizen/bin/cz", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/cli.py", line 570, in main
    args.func(conf, arguments)()
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/commands/info.py", line 13, in __call__
    out.write(self.cz.info())
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/out.py", line 13, in write
    print(value, *args)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 1068: ordinal not in range(256)

I was running into that problem on MacOS (Ventura 13.6.3) and AlmaLinux 8.9.

Same exception also happens when issuing 'cz init' quite at the end of the process:

[xx@xxxxxxxx:~/tmp/test-git-repo (master +)] $ cz init
Welcome to commitizen!

Answer the questions to configure your project.
For further configuration visit:

https://commitizen-tools.github.io/commitizen/config/

? Please choose a supported config file:  .cz.toml
? Please choose a cz (commit rule): (default: cz_conventional_commits) cz_conventional_commits
? Choose the source of the version: commitizen: Fetch and set version in commitizen config (default)
No Existing Tag. Set tag to v0.0.1
? Choose version scheme:  semver
? Please enter the correct version format: (default: "$version")
? Create changelog automatically on bump Yes
? Keep major version zero (0.x) during breaking changes Yes
? What types of pre-commit hook you want to install? (Leave blank if you don't want to install) done

You can bump the version running:

	cz bump

Traceback (most recent call last):
  File "/home/user/pb/venv_commitizen/bin/cz", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/cli.py", line 570, in main
    args.func(conf, arguments)()
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/commands/init.py", line 150, in __call__
    out.success("Configuration complete \U0001f680")
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/out.py", line 28, in success
    line(message)
  File "/home/user/pb/venv_commitizen/lib/python3.11/site-packages/commitizen/out.py", line 18, in line
    print(value, *args, **kwargs)
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f680' in position 28: ordinal not in range(256)

This probably happens also with other non UTF-8 encoded Terminals.

We have quite a few machines that still run (due to the application running on them) in ISO8859-1 Encoding

Steps to reproduce

  1. Start new Terminal
  2. Set LANG to 'de_CH.ISO8859-1' with 'export LANG=de_CH.ISO8859-1'
  3. issue 'cz info'

Current behavior

Exception / Crash

Desired behavior

optimum:
Proper output with reencoding also with other Terminal Encodings than UTF-8. (This is due the fact that we have to use ISO8859-1 Terminal for development and therefore also use git and cz inside these terminals)

Acceptable but not desireable:
Prevent cz from being used with non UTF-8 Termial: warn and exit at start instead of throwing an exception in the middle of the work.

Screenshots

No response

Environment

cz version --report
Commitizen Version: 3.13.0
Python Version: 3.11.6 (main, Oct 3 2023, 17:06:54) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)]
Operating System: Linux

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions