json object for FileNotFound

When a nonexistant file is passed to a command and  --json-error-messages
is enabled, output a JSON object indicating the problem.

(But git ls-files --error-unmatch still displays errors about such files in
some situations.)

I don't like the duplication of the name of the command introduced by this,
but I can't see a great way around it. One way would be to pass the Command
instead.

When json is not enabled, the stderr is unchanged. This is necessary
because some commands like find have custom output. So dislaying
"find foo not found" would be wrong. So had to complicate things with
toplevelFileProblem having different output with and without json.

When not using --json-error-messages but still using --json, it displays
the error to stderr, but does display a json object without the error. It
does have an errorid though. Unsure how useful that behavior is.

Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
Joey Hess 2023-04-25 19:26:20 -04:00
parent 91ba0cc7fd
commit be36e208c2
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
29 changed files with 97 additions and 43 deletions

View file

@ -119,7 +119,7 @@ seek o = startConcurrency commandStages $ do
-- are not known to git yet, since this will add
-- them. Instead, have workTreeItems warn about other
-- problems, like files that don't exist.
let ww = WarnUnmatchWorkTreeItems
let ww = WarnUnmatchWorkTreeItems "add"
l <- workTreeItems ww (addThese o)
let go b a = a ww (commandAction . gofile b) l
unless (updateOnly o) $

View file

@ -60,7 +60,7 @@ seek' o fto = startConcurrency (Command.Move.stages fto) $ do
Batch fmt -> batchOnly (keyOptions o) (copyFiles o) $
batchAnnexed fmt seeker keyaction
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "copy"
seeker = AnnexedFileSeeker
{ startAction = start o fto

View file

@ -74,7 +74,7 @@ seek o = startConcurrency commandStages $ do
Batch fmt -> batchOnly (keyOptions o) (dropFiles o) $
batchAnnexed fmt seeker (startKeys o from)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "drop"
start :: DropOptions -> Maybe Remote -> SeekInput -> RawFilePath -> Key -> CommandStart
start o from si file key = start' o from key afile ai si

View file

@ -192,4 +192,4 @@ seek o = withOtherTmp $ \tmpdir -> do
c <- inRepo $ Git.commitTree cmode cmessage [] t
liftIO $ putStrLn (fromRef c)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "filter-branch"

View file

@ -75,7 +75,7 @@ seek o = do
Batch fmt -> batchOnly (keyOptions o) (findThese o) $
batchAnnexedFiles fmt seeker
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "find"
-- Default to needing content to be present, but if the user specified a
-- limit, content does not need to be present.

View file

@ -35,7 +35,7 @@ seek :: CmdParams -> CommandSeek
seek ps = unlessM crippledFileSystem $
withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "fix"
seeker = AnnexedFileSeeker
{ startAction = start FixAll
, checkContentPresent = Nothing

View file

@ -113,7 +113,7 @@ seek o = startConcurrency commandStages $ do
cleanupIncremental i
void $ tryIO $ recordActivity Fsck u
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "fsck"
checkDeadRepo :: UUID -> Annex ()
checkDeadRepo u =

View file

@ -53,7 +53,7 @@ seek o = startConcurrency transferStages $ do
Batch fmt -> batchOnly (keyOptions o) (getFiles o) $
batchAnnexed fmt seeker (startKeys from)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "get"
start :: GetOptions -> Maybe Remote -> SeekInput -> RawFilePath -> Key -> CommandStart
start o from si file key = start' expensivecheck from key afile ai si

View file

@ -49,7 +49,7 @@ seek o = do
withFilesInGitAnnex ww seeker
=<< workTreeItems ww (inprogressFiles o)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "inprogress"
start :: IsTerminal -> S.Set Key -> SeekInput -> RawFilePath -> Key -> CommandStart
start isterminal s _si _file k

View file

@ -56,7 +56,7 @@ seek o = do
}
withFilesInGitAnnex ww seeker =<< workTreeItems ww (listThese o)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "list"
getList :: ListOptions -> Annex [(UUID, RemoteName, TrustLevel)]
getList o

View file

@ -32,7 +32,7 @@ cmd = withAnnexOptions [jsonOptions, annexedMatchingOptions] $
seek :: CmdParams -> CommandSeek
seek ps = withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "lock"
seeker = AnnexedFileSeeker
{ startAction = start
, checkContentPresent = Nothing

View file

@ -105,7 +105,7 @@ seek o = ifM (null <$> Annex.Branch.getUnmergedRefs)
, giveup "This repository is read-only, and there are unmerged git-annex branches, which prevents displaying location log changes. (Set annex.merge-annex-branches to false to ignore the unmerged git-annex branches.)"
)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "log"
start :: LogOptions -> (FilePath -> Outputter) -> SeekInput -> RawFilePath -> Key -> CommandStart
start o outputter _ file key = do

View file

@ -76,7 +76,7 @@ seek :: MetaDataOptions -> CommandSeek
seek o = case batchOption o of
NoBatch -> do
c <- currentVectorClock
let ww = WarnUnmatchLsFiles
let ww = WarnUnmatchLsFiles "metadata"
let seeker = AnnexedFileSeeker
{ startAction = start c o
, checkContentPresent = Nothing

View file

@ -41,7 +41,7 @@ optParser desc = MigrateOptions
seek :: MigrateOptions -> CommandSeek
seek o = withFilesInGitAnnex ww seeker =<< workTreeItems ww (migrateThese o)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "migrate"
seeker = AnnexedFileSeeker
{ startAction = start o
, checkContentPresent = Nothing

View file

@ -50,7 +50,7 @@ seek o = startConcurrency stages $
stages = case fromToOptions o of
FromRemote _ -> transferStages
ToRemote _ -> commandStages
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "mirror"
seeker = AnnexedFileSeeker
{ startAction = start o
, checkContentPresent = Nothing

View file

@ -84,7 +84,7 @@ seek' o fto = startConcurrency (stages fto) $ do
, usesLocationLog = True
}
keyaction = startKey fto (removeWhen o)
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "move"
stages :: FromToHereOptions -> UsedStages
stages (FromOrToRemote (FromRemote _)) = transferStages

View file

@ -131,7 +131,7 @@ send ups fs = do
-- expensive.
starting "sending files" (ActionItemOther Nothing) (SeekInput []) $
withTmpFile "send" $ \t h -> do
let ww = WarnUnmatchLsFiles
let ww = WarnUnmatchLsFiles "multicast"
(fs', cleanup) <- seekHelper id ww LsFiles.inRepo
=<< workTreeItems ww fs
matcher <- Limit.getMatcher

View file

@ -32,10 +32,10 @@ cmd = command "pre-commit" SectionPlumbing
seek :: CmdParams -> CommandSeek
seek ps = do
let ww = WarnUnmatchWorkTreeItems
let ww = WarnUnmatchWorkTreeItems "pre-commit"
l <- workTreeItems ww ps
-- fix symlinks to files being committed
flip withFilesToBeCommitted l $ \(si, f) -> commandAction $
flip (withFilesToBeCommitted ww) l $ \(si, f) -> commandAction $
maybe stop (Command.Fix.start Command.Fix.FixSymlinks si f)
=<< isAnnexLink f
-- after a merge conflict or git cherry-pick or stash, pointer

View file

@ -794,7 +794,7 @@ seekSyncContent o rs currbranch = do
in seekFiltered (const (pure True)) filterer $
seekHelper id ww (LsFiles.inRepoOrBranch origbranch) l
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "sync"
gofile bloom mvar _ f k =
go (Right bloom) mvar (AssociatedFile (Just f)) k

View file

@ -30,7 +30,7 @@ cmd = withAnnexOptions [annexedMatchingOptions] $
seek :: CmdParams -> CommandSeek
seek ps = withFilesInGitAnnex ww (seeker False) =<< workTreeItems ww ps
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "unannex"
seeker :: Bool -> AnnexedFileSeeker
seeker fast = AnnexedFileSeeker

View file

@ -53,13 +53,13 @@ seek ps = do
l <- workTreeItems ww ps
withFilesNotInGit
(CheckGitIgnore False)
WarnUnmatchWorkTreeItems
(WarnUnmatchWorkTreeItems "uninit")
checksymlinks
l
withFilesInGitAnnex ww (Command.Unannex.seeker True) l
finish
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "uninit"
checksymlinks (_, f) =
commandAction $ lookupKey f >>= \case
Nothing -> stop

View file

@ -33,7 +33,7 @@ mkcmd n d = withAnnexOptions [jsonOptions, annexedMatchingOptions] $
seek :: CmdParams -> CommandSeek
seek ps = withFilesInGitAnnex ww seeker =<< workTreeItems ww ps
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "unlock"
seeker = AnnexedFileSeeker
{ startAction = start
, checkContentPresent = Nothing

View file

@ -64,7 +64,7 @@ seek o = do
Batch fmt -> batchOnly (keyOptions o) (whereisFiles o) $
batchAnnexed fmt seeker (startKeys o m)
where
ww = WarnUnmatchLsFiles
ww = WarnUnmatchLsFiles "whereis"
start :: WhereisOptions -> M.Map UUID Remote -> SeekInput -> RawFilePath -> Key -> CommandStart
start o remotemap si file key =