arduino / arduino-cli

Arduino command line tool
https://arduino.github.io/arduino-cli/latest/
GNU General Public License v3.0
4.23k stars 370 forks source link

Silence "config warnings" in text mode, except for `config ...` commands #2641

Closed cmaglie closed 2 weeks ago

cmaglie commented 2 weeks ago

Please check if the PR fulfills these requirements

See how to contribute

What kind of change does this PR introduce?

Prints configuration warnings in text mode only if running one of the config ... commands. Previously if there was an error in the configuration file, the warning was printed on all commands run from the cli. In JSON mode the warning is always returned.

Also improve the error message from:

schema not defined for key 'asdasd'

to

Invalid value in configuration: schema not defined for key 'asdasd'

What is the current behavior?

$ arduino-cli version 
schema not defined for key 'asdasd'
arduino-cli  Version: 0.0.0-git Commit:  Date: 
$ arduino-cli version --json
{
  "Application": "arduino-cli",
  "Commit": "",
  "Date": "",
  "Status": "",
  "VersionString": "0.0.0-git",
  "warnings": [
    "schema not defined for key 'asdasd'"
  ]
}
$ arduino-cli config get directories.data
schema not defined for key 'asdasd'
/home/cmaglie/.arduino15

What is the new behavior?

$ arduino-cli version
arduino-cli  Version: 0.0.0-git Commit:  Date: 
$ arduino-cli version --json
{
  "Application": "arduino-cli",
  "Commit": "",
  "Date": "",
  "Status": "",
  "VersionString": "0.0.0-git",
  "warnings": [
    "Invalid value in configuration: schema not defined for key 'asdasd'"
  ]
}
$ arduino-cli config get directories.data
Invalid value in configuration: schema not defined for key 'asdasd'
/home/cmaglie/.arduino15

Does this PR introduce a breaking change, and is titled accordingly?

Other information

Partially fix #2638

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.28%. Comparing base (3f0d43f) to head (0beb1b6). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2641 +/- ## ========================================== - Coverage 70.29% 70.28% -0.02% ========================================== Files 222 222 Lines 21308 21309 +1 ========================================== - Hits 14978 14976 -2 - Misses 5153 5155 +2 - Partials 1177 1178 +1 ``` | [Flag](https://app.codecov.io/gh/arduino/arduino-cli/pull/2641/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=arduino) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/arduino/arduino-cli/pull/2641/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=arduino) | `70.28% <100.00%> (-0.02%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=arduino#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

cmaglie commented 2 weeks ago

Is it intentional that when requesting the command below the json output omits the warnings key, but when requesting with a subcommand different from config the warnings key appears?

Yes, that's because the returned JSON is a string and there is no way to fit a warning field inside. We should have made it an object instead, like:

{
  "value": "/home/ale/.arduino15",
  "warnings": [
    "Invalid value in configuration: schema not defined for key 'asldfasdfasdf'"
  ]
}

but now it's too late, it would be for CLI 2.0.0 :-)