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

Handle inappropriate null output from arduino-cli core list when no platforms are installed #311

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

per1234
Copy link
Collaborator

@per1234 per1234 commented Aug 13, 2024

A regression was introduced in the 1.0.0 release of Arduino CLI (arduino/arduino-cli#2690). When no platforms are installed, arduino-cli core list --format json now returns null instead of the appropriate value of an empty array.

Previously the code for parsing the output was written under the assumption of the logical behavior of the command always outputting an array, even if an empty array. This code could not correctly handle the output produced by Arduino CLI >=1.0.0, resulting in a spurious failure of the action (#310):

Traceback (most recent call last):
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 1709, in <module>
    main()  # pragma: no cover
    ^^^^^^
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 63, in main
    compile_sketches.compile_sketches()
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 219, in compile_sketches
    self.install_platforms()
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 337, in install_platforms
    self.install_platforms_from_repository(platform_list=platform_list.repository)
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 629, in install_platforms_from_repository
    destination_path = self.get_platform_installation_path(platform=platform)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 562, in get_platform_installation_path
    for installed_platform in installed_platform_list:
TypeError: 'NoneType' object is not iterable

In order to work around the Arduino CLI bug, code is added to handle the case where the value is null (None when converted to a Python data type) instead of an array.


Fixes #310

…no platforms are installed

A regression was introduced in the 1.0.0 release of Arduino CLI. When no platforms are installed, `arduino-cli core list
--format json` now returns `null` instead of the appropriate value of an empty array.

Previously the code for parsing the output was written under the assumption of the logical behavior of the command
always outputting an array, even if an empty array. This code could not correctly handle the output produced by Arduino
CLI >=1.0.0, resulting in a spurious failure of the action:

```
Traceback (most recent call last):
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 1709, in <module>
    main()  # pragma: no cover
    ^^^^^^
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 63, in main
    compile_sketches.compile_sketches()
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 219, in compile_sketches
    self.install_platforms()
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 337, in install_platforms
    self.install_platforms_from_repository(platform_list=platform_list.repository)
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 629, in install_platforms_from_repository
    destination_path = self.get_platform_installation_path(platform=platform)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/_actions/arduino/compile-sketches/main/compilesketches/compilesketches.py", line 562, in get_platform_installation_path
    for installed_platform in installed_platform_list:
TypeError: 'NoneType' object is not iterable
```

In order to work around the Arduino CLI bug, code is added to handle the case where the value is `null` (`None` when
converted to a Python data type) instead of an array.
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Aug 13, 2024
@per1234 per1234 self-assigned this Aug 13, 2024
@per1234 per1234 merged commit 8ac27e9 into arduino:main Aug 13, 2024
25 checks passed
@per1234 per1234 deleted the handle-core-list-null branch August 13, 2024 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attempting to use arduino:avr git repository as source-url results in compilesketches.py crashing
1 participant