Skip to content
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

[BUG] \U0001f40d character causes an error when running jake through a batch file on windows #67

Closed
blades opened this issue Oct 11, 2021 · 1 comment · Fixed by #70
Closed
Labels
bug Something isn't working

Comments

@blades
Copy link

blades commented Oct 11, 2021

The human-readable header information appears to cause an exception due to windows-incompatible characters being output.

I'm attempting to run jake on a windows machine through a batch file against a conda environment.
There's a line in the batch file as follows:

conda list | jake ddt -c -q

This should pass the conda list of packages through to jake and generate the usual output. However, this throws the following exception instead:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\yaspin\core.py", line 360, in _spin
    sys.stdout.write(out)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 187, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\users\win10_64bit\.conda\envs\jake-test\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 '\u280b' in position 0: character maps to <undefined>

Traceback (most recent call last):
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Win10_64bit\.conda\envs\jake-test\Scripts\jake.exe\__main__.py", line 9, in <module>
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\jake\__main__.py", line 233, in ddt
    spinner.ok("?? ")
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\yaspin\core.py", line 325, in ok
    self._freeze(_text)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\yaspin\core.py", line 344, in _freeze
    sys.stdout.write(self._last_frame)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 41, in write
    self.__convertor.write(text)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 162, in write
    self.write_and_convert(text)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 187, in write_and_convert
    self.write_plain_text(text, cursor, start)
  File "c:\users\win10_64bit\.conda\envs\jake-test\lib\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
    self.wrapped.write(text[start:end])
  File "c:\users\win10_64bit\.conda\envs\jake-test\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 '\U0001f40d' in position 0: character maps to <undefined>

The culprit is this information at the top of the output:

�[?25h??  Collecting Dependencies
�[?25h??  Querying OSS Index
�[?25h??  Auditing results from OSS Index

If the output is set to JSON then the error no longer occurs (because that's no longer output). Note that this works when issued as a command at the command prompt as expected - it's only when it's run via a batch file that this exception is thrown, for some reason.

  • OS: Windows 10 Pro
  • Python Version: 3.6.2
  • Jake Version: 0.2.77

One simple option would be to strip that heading information away and only leave the reasults when '-q' is used as a switch, but the preferred option would probably be to use characters that wouldn't cause problems under windows at all.

@madpah
Copy link
Collaborator

madpah commented Oct 21, 2021

We believe the UnicodeEncodeError is caused by CycloneDX/cyclonedx-python-lib#39 for which a fix is being worked on @blades

madpah added a commit that referenced this issue Oct 21, 2021
fix: character encoding issues on Windows #67

Signed-off-by: Paul Horton <phorton@sonatype.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants