--json-exceptions

Added a --json-exceptions option, which makes some exceptions be output in json.

The distinction is that --json-error-messages is for messages relating
to a particular ActionItem, while --json-exceptions is for messages that
are not, eg ones for a file that does not exist.

It's unfortunate that we need two switches with such a fine distinction
between them, but I'm worried about maintaining backwards compatability
in the json output, to avoid breaking anything that parses it, and this was
the way to make sure I didn't.

toplevelWarning is generally used for the latter kind of message. And
the other calls to toplevelWarning could be converted to showException. The
only possible gotcha is that if toplevelWarning is ever called after
starting acting on a file, it will add to the --json-error-messages of the
json displayed for that file and converting to showException would be a
behavior change. That seems unlikely, but I didn't convery everything to
avoid needing to satisfy myself it was not a concern.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2023-04-25 17:02:25 -04:00
parent a474c9c63b
commit a325524454
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
32 changed files with 304 additions and 81 deletions

View file

@ -568,9 +568,9 @@ workTreeItems' (AllowHidden allowhidden) ww ps = case ww of
let p' = toRawFilePath p
relf <- liftIO $ relPathCwdToFile p'
ifM (not <$> (exists p' <||> hidden currbranch relf))
( prob (QuotedPath (toRawFilePath p) <> " not found")
( prob FileNotFound (QuotedPath (toRawFilePath p) <> " not found")
, ifM (viasymlink stopattop (upFrom relf))
( prob (QuotedPath (toRawFilePath p) <> " is beyond a symbolic link")
( prob FileBeyondSymbolicLink (QuotedPath (toRawFilePath p) <> " is beyond a symbolic link")
, return True
)
)
@ -605,8 +605,8 @@ workTreeItems' (AllowHidden allowhidden) ww ps = case ww of
<$> catObjectMetaDataHidden f currbranch
| otherwise = return False
prob msg = do
toplevelWarning False msg
prob eid msg = do
showException False eid msg
Annex.incError
return False