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

Redirecting pio pkg list output crashes #5053

Open
1 task done
AgainPsychoX opened this issue Dec 20, 2024 · 1 comment
Open
1 task done

Redirecting pio pkg list output crashes #5053

AgainPsychoX opened this issue Dec 20, 2024 · 1 comment

Comments

@AgainPsychoX
Copy link

What kind of issue is this?

  • PlatformIO Core.
    If you’ve found a bug, please provide an information below.

Configuration

Operating system: Windows 10

PlatformIO Version (platformio --version): PlatformIO Core, version 6.1.16

Description of problem

Steps to Reproduce

  1. Open PlatformIO CLI enabled PowerShell terminal
  2. Try pio pkg list
  3. Then try pio pkg list > file.log

Actual Results

  1. Works.
  2. Crashes.
PS D:\Projects\+embedded\YellowToyCar> pio pkg list > xd.log
UnicodeEncodeError: Traceback (most recent call last):
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\__main__.py", line 103, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\cli.py", line 85, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\package\commands\list.py", line 56, in package_list_cmd
    list_project_packages(options)
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\package\commands\list.py", line 179, in list_project_packages
    _found = print_project_env_platform_packages(env, options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\package\commands\list.py", line 205, in print_project_env_platform_packages
    print_dependency_tree(
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\package\commands\list.py", line 99, in print_dependency_tree
    click.echo(
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\__main__.py", line 89, in <lambda>
    click.echo = lambda *args, **kwargs: _safe_echo(0, *args, **kwargs)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\platformio\__main__.py", line 83, in _safe_echo
    click_echo_origin[origin](*args, **kwargs)
  File "C:\Users\PsychoX\.platformio\penv\Lib\site-packages\click\utils.py", line 318, in echo
    file.write(out)  # type: ignore
    ^^^^^^^^^^^^^^^
  File "C:\Users\PsychoX\.platformio\python3\Lib\encodings\cp1250.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to <undefined>

file.log:

Resolving esp32cam dependencies...
Platform espressif32 @ 6.8.1 (required: espressif32 @ ^6.8.1)

Expected Results

I just wanted to redirect the command output to the file, just save to file to ease reading hundreds of lines long output...

If problems with PlatformIO Build System:

The content of platformio.ini:

; PlatformIO Project Configuration File
;
; Since ESP-IDF is used, quite a lot is configured ESP-IDF ways, incl. CMake.
; Dependencies are managed by ESP-IDF (components) and by Git submodules.
; See `CMakeLists.txt` files and `idf_component.yml`.

[platformio]
default_envs = esp32s3eye_debug

[base]
platform = espressif32@^6.8.1
framework = espidf
monitor_speed = 115200
monitor_filters = 
	default
	esp32_exception_decoder
	time
	log2file
extra_scripts = 
	pre:scripts/pio/gzip_web_embeds.py
	scripts/pio/extra_c_cpp_properties.py
board_build.embed_files =
	src/index.html.gz

[env:esp32cam] # aka AI-Thinker
extends = base
board = esp32cam
build_flags = -DMODEL_ESP32CAM
build_type = release

[env:esp32cam_debug]
extends = base, env:esp32cam
build_type = debug

[env:esp32s3eye] # WROOM N16R8
extends = base
board = esp32-s3-devkitc-1
board_build.arduino.memory_type = qio_opi
board_build.arduino.partitions = default_16MB.csv
board_build.flash_mode = qio
board_build.psram_type = opi
board_upload.flash_size = 16MB
board_upload.maximum_size = 16777216
board_upload.speed = 921600
board_build.extra_flags = -DBOARD_HAS_PSRAM
build_flags = -DMODEL_ESP32S3EYE
build_type = release

[env:esp32s3eye_debug]
extends = base, env:esp32s3eye
build_type = debug

(idk, if useful, but flexing ;) )

Source file to reproduce issue: N/A

Additional info

Any redirection causes similar problem, incl. pio pkgs list | more.

@hhrhhr
Copy link

hhrhhr commented Dec 29, 2024

This error occurs even without a project (pio pkg list -g | more). If you replace utf-8 characters with something simple ("!--", "+--"), the error does not occur:

"│ " * level,
"├──" if index < len(candidates) - 1 else "└──",

But:

click.echo(message=None, file=None, nl=True, err=False, color=None)
Print a message and newline to stdout or a file. This should be used instead of print() because it provides better support for different data, files, and environments.

Compared to print(), this does the following:
Supports Unicode in the Windows console.
Supports colors and styles on Windows.

Changed in version 6.0: Support Unicode output on the Windows console. Click does not modify sys.stdout, so sys.stdout.write() and print() will still not support Unicode.

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

No branches or pull requests

2 participants