Skip to content

Missing handling of new output formats #1635

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

Closed
per1234 opened this issue Jan 24, 2022 · 0 comments · Fixed by #2003
Closed

Missing handling of new output formats #1635

per1234 opened this issue Jan 24, 2022 · 0 comments · Fixed by #2003
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Jan 24, 2022

Bug Report

Current behavior

Some output is not printed in the format specified by the user when they use the new jsonmini or yaml options (#1586, #1600) with the --format flag.

This misformatted output breaks machine readability.

For example:

$ arduino-cli version
arduino-cli.exe  Version: nightly-20220124 Commit: 530e671 Date: 2022-01-24T01:28:27Z

$ arduino-cli lib search --format jsonmini Arduino_MKRRGB
Updating index: library_index.json.gz downloaded ?  18677.76% 00m02ss
Updating index: library_index.json.sig downloaded
{"libraries":[{"name":"Arduino_MKRRGB","releases":{"1.0.0":{"author":"Arduino","version":"1.0.0","maintainer":"Arduino \[email protected]\u003e","sentence":"Allows you to draw on your MKR RGB shield.","paragraph":"Depends on the ArduinoGraphics library.","website":"http://github.com/arduino-libraries/Arduino_MKRRGB","category":"Display","architectures":["samd"],"types":["Arduino"],"resources":{"url":"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip","archive_filename":"Arduino_MKRRGB-1.0.0.zip","checksum":"SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d","size":7797,"cache_path":"libraries"},"provides_includes":["Arduino_MKRRGB.h"],"dependencies":[{"name":"ArduinoGraphics"}]}},"latest":{"author":"Arduino","version":"1.0.0","maintainer":"Arduino \[email protected]\u003e","sentence":"Allows you to draw on your MKR RGB shield.","paragraph":"Depends on the ArduinoGraphics library.","website":"http://github.com/arduino-libraries/Arduino_MKRRGB","category":"Display","architectures":["samd"],"types":["Arduino"],"resources":{"url":"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip","archive_filename":"Arduino_MKRRGB-1.0.0.zip","checksum":"SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d","size":7797,"cache_path":"libraries"},"provides_includes":["Arduino_MKRRGB.h"],"dependencies":[{"name":"ArduinoGraphics"}]}}],"status":1}

$ arduino-cli lib search --format jsonmini Arduino_MKRRGB | jq '.libraries[0].latest.version'
jq: error (at <stdin>:1): Cannot index number with string "libraries"
parse error: Invalid numeric literal at line 1, column 6

$ arduino-cli lib search --format json Arduino_MKRRGB | jq '.libraries[0].latest.version'
"1.0.0"

$ arduino-cli lib search --format yaml Arduino_MKRRGB
Updating index: library_index.json.gz downloaded ?  19660.80% 00m02ss
Updating index: library_index.json.sig downloaded
libraries:
- name: Arduino_MKRRGB
  releases:
    1.0.0:
      author: Arduino
      version: 1.0.0
      maintainer: Arduino <[email protected]>
      sentence: Allows you to draw on your MKR RGB shield.
      paragraph: Depends on the ArduinoGraphics library.
      website: http://github.com/arduino-libraries/Arduino_MKRRGB
      category: Display
      architectures:
      - samd
      types:
      - Arduino
      resources:
        url: https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip
        archivefilename: Arduino_MKRRGB-1.0.0.zip
        checksum: SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d
        size: 7797
        cachepath: libraries
      license: ""
      providesincludes:
      - Arduino_MKRRGB.h
      dependencies:
      - name: ArduinoGraphics
        versionconstraint: ""
  latest:
    author: Arduino
    version: 1.0.0
    maintainer: Arduino <[email protected]>
    sentence: Allows you to draw on your MKR RGB shield.
    paragraph: Depends on the ArduinoGraphics library.
    website: http://github.com/arduino-libraries/Arduino_MKRRGB
    category: Display
    architectures:
    - samd
    types:
    - Arduino
    resources:
      url: https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip
      archivefilename: Arduino_MKRRGB-1.0.0.zip
      checksum: SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d
      size: 7797
      cachepath: libraries
    license: ""
    providesincludes:
    - Arduino_MKRRGB.h
    dependencies:
    - name: ArduinoGraphics
      versionconstraint: ""
status: 1

The code here does not handle the new formats:

if OutputFormat != "json" {

Expected behavior

All output is printed in the specified format.


A single centralized function is used to determine when output is set to a machine readable format instead of the current jumble of "magic strings" scattered throughout the codebase, which handle only "json".

Environment

  • CLI version: nightly-20220124 Commit: 530e671 Date: 2022-01-24T01:28:27Z
  • OS and platform: Windows 10

Additional context

#1872 is one specific instance of this general bug.


Originally reported (peripherally) at #1624

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Jan 24, 2022
@per1234 per1234 assigned cmaglie and unassigned silvanocerza Dec 16, 2022
@per1234 per1234 added the conclusion: resolved Issue was resolved label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
3 participants