Please describe the problem.
As I understand the manual:
Options
--json --json-error-messages
are provided so that another program can parse thegit annex fsck
results.Option
--quiet
is provided to list only problems (not print anything for OK files).
However, when options are combined, only plain text error messages are provided, no json output is provided.
I understand this may be "as designed", quiet is quiet... But then how to log only errors in json? I have +300k files in the annex, and no need to log when everything is fine.
What steps will reproduce the problem?
Create a repo with files b and c
Corrupt file b
git annex fsck --json --json-error-messages --quiet
I expected to have a json output with only files that fail the fsck, instead I get only normal stderr, just like with
git annex fsck --quiet
What version of git-annex are you using? On what operating system?
10.20230926-12 on arch
Please provide any additional information below.
# Expected plain result
> git annex fsck
fsck b
** No known copies exist of b
failed
fsck c (checksum...) ok
(recording state in git...)
fsck: 1 failed
# Expected json result (error message to stderr, both logs)
> git annex fsck --json
** No known copies exist of b
{"command":"fsck","dead":[],"error-messages":[],"file":"b","input":["b"],"key":"SHA256E-s5--f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2","success":false,"untrusted":[]}
{"command":"fsck","error-messages":[],"file":"c","input":["c"],"key":"SHA256E-s4--530a0b93b8c1ea618546d3aaa6ec71f888d2a6095322bfdb1b04c9225e26481e","note":"checksum...","success":true}
fsck: 1 failed
# Expected json output with error message embedded
> git annex fsck --json --json-error-messages
{"command":"fsck","dead":[],"error-messages":["** No known copies exist of b"],"file":"b","input":["b"],"key":"SHA256E-s5--f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2","success":false,"untrusted":[]}
{"command":"fsck","error-messages":[],"file":"c","input":["c"],"key":"SHA256E-s4--530a0b93b8c1ea618546d3aaa6ec71f888d2a6095322bfdb1b04c9225e26481e","note":"checksum...","success":true}
fsck: 1 failed
# Expected only error message
> git annex fsck --quiet
** No known copies exist of b
fsck: 1 failed
# UnExpected result: I expected a json output with the error message embedded "--json --json-error-messages" seem ignored here
> git annex fsck --json --json-error-messages --quiet
** No known copies exist of b
fsck: 1 failed
# End of transcript or log.
Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
Yes, great tool ! Thanks !
Hmm, I've never considered combining --quiet with --json. It's kind of undefined and really not clear to me what it should do.
But, --json-error-messages makes the json contain an error-messages field, and the error message is in there. So you can just extract that and ignore the other messages in the json output. No need to use --quiet then.
I suppose there may be someone who uses --json as a matter of course, but adds --quiet to that when they want to disable the json output. So changing the current behavior, ill-defined as it is, would be asking for trouble.
What actually happens currently is which ever output option comes last overrides earlier options. So
--json --quiet
is quiet, and--quiet --json
outputs json.--json-error-messages
is like--json
in this regard to. Which is just behavior that fell out of the option parser implementation.