metadata --batch: Avoid crashing when a non-annexed file is input
Turns out that CommandStart actions do not have their exceptions caught, which is why the giveup was causing a crash. Mostly these actions do not do very much work on their own, but it does seem possible there are other commands whose CommandStart also throws an exception. So, my first attempt at a fix was to catch those exceptions. But, --json-error-messages then causes a difficulty, because in order to output a json error message, an action needs to have been started; that sets up the json object that the error message will be included in a field of. While it would be possible to output an object with just an error field, this would be json output of a format that the user has no reason to expect, that happens only in an exceptional circumstance. That is something I have always wanted to avoid with the json output; while git-annex man pages don't document what the json looks like, the output has always been made to be self-describing. Eg, it includes "error-messages":[] even when there's no errors. With that ruled out, it doesn't seem a good idea to catch CommandStart exceptions and display the error to stderr when --json-error-messages is set. And so I don't know if it makes sense to catch exceptions from that at all. Maybe I'd have a different opinion if --json-error-messages did not exist though. So instead, output a blank line like other batch commands do. This also leaves open the possibility of implementing support for matching object with metadata --json, which would also want to output a blank line when the input didn't match. Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
parent
2981b0fbc9
commit
80f1354685
5 changed files with 27 additions and 6 deletions
|
@ -4,3 +4,5 @@ When invoking `git-annex metadata --batch --json --json-error-messages`, if an e
|
|||
|
||||
[[!meta author=jwodder]]
|
||||
[[!tag projects/dandi]]
|
||||
|
||||
> [[fixed|done]] --[[Joey]]
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
[[!comment format=mdwn
|
||||
username="joey"
|
||||
subject="""comment 1"""
|
||||
date="2021-11-01T16:27:48Z"
|
||||
content="""
|
||||
For consistency with other --batch, I've made it reply with a blank line
|
||||
when the input is not an annexed file.
|
||||
|
||||
Do note that --json-error-messages cannot cram every possible kind of error
|
||||
message into a json object. In particular, errors that occur at startup,
|
||||
and not when acting on a particular file or key, do not fit into the json
|
||||
schema.
|
||||
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue