Skip to content

JSON Response to lib Commands #96

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
GItThatSparrow opened this issue Dec 2, 2018 · 5 comments
Closed

JSON Response to lib Commands #96

GItThatSparrow opened this issue Dec 2, 2018 · 5 comments
Labels
type: enhancement Proposed improvement

Comments

@GItThatSparrow
Copy link

GItThatSparrow commented Dec 2, 2018

AS A User

I NEED TO determine the result of a call to the arduino-cli based on the response
AND the command specifies the --format=json parameter

SO THAT I can distinguish the difference in between a successful operation and a failed operation


Example

I issue a command like

>> arduino-cli lib install [email protected] --format=json

But the response is empty, like:

>> arduino-cli lib install [email protected] --format=json

>>

Equivalent example download

Same result when I issue a command like

>> arduino-cli lib download AudioZero --format=json   # or...
>> arduino-cli lib download [email protected] --format=json

But the response is empty, like:

>> arduino-cli lib download AudioZero --format=json # or....

>>
>> arduino-cli lib download [email protected] --format=json

>>

Equivalent example list

Same result when I issue a command like

>> arduino-cli lib list --format=json

But the response is empty, like:

>> arduino-cli lib list --format=json

>>

Equivalent example uninstall

Same result when I issue a command like

>> arduino-cli lib uninstall [email protected] --format=json

But the response is empty, like:

>> arduino-cli lib uninstall [email protected] --format=json

>>

Equivalent example update-index

Same result when I issue a command like

>> arduino-cli lib update-index --format=json

But the response is empty, like:

>> arduino-cli lib update-index --format=json

>>

Equivalent example upgrade

Same result when I issue a command like

>> arduino-cli lib upgrade --format=json

But the response is empty, like:

>> arduino-cli lib upgrade --format=json

>>
@philippejadin
Copy link

This is really important. I'm working on a python wrapper to have a thin compile server installable on clients (ala codebender, but running locally), and having some json return all the time is mandatory. Even if the json contains just error = true / error = false
See for instance this article : https://nordicapis.com/best-practices-api-error-handling/

In the meantime, I will check if the error codes returned are consistent (I hope they are :-) )

@per1234 per1234 added the type: enhancement Proposed improvement label May 24, 2019
@mastrolinux
Copy link
Contributor

@philippejadin you can probably now use the new GRPC interface. This bug is still confirmed and I am not use if best to return an empty json or something like {'success': 'true', 'message': 'some message here or empty string'}

@masci
Copy link
Contributor

masci commented Jul 18, 2019

I think when invoking the CLI process the source of truth should always be the process exit code.

If the exit code is 0 operation was successful, otherwise you should make no assumptions about what's in the standard error/output: instead, you would look at the meaning of the exit code. Think about the CLI exiting because of a panic when likely the program wasn't able to properly print any output message, let alone a JSON structured message.

Different topic is whether printing an empty JSON object {} or nothing at all when the command succeeds but the result is empty. I personally like the docker approach, where nothing is printed if the response was empty (try doing docker ps --format='{{json .}}' vs docker ps when no containers are running).

@mastrolinux
Copy link
Contributor

ok to have completely no output, it respects the UNIX phylosophy. I believe now the main issue is some commands returns code different from 0 even if the command run successfully (i.e. running twice lib install with the same libs)

@masci
Copy link
Contributor

masci commented Aug 28, 2019

The expected behavior is:

  • exit code of the CLI determines the status of the operation requested (success/fail)
  • JSON output is only considered valid when the exit code is 0

I'm going to close this as what we have in master works as described.

@masci masci closed this as completed Aug 28, 2019
per1234 added a commit that referenced this issue Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

5 participants