fix(codeartifact): log unexpected I/O errors in existingFileMatches (#4769)

Follow-up hectorvent flagged on #4708 (approved, merged): the catch
blocks in existingFileMatches returned false silently for both a
routine missing file and any other I/O error reading an existing
asset, with no log line either way, which AGENTS.md's exception-handling
rule doesn't allow for a case that isn't genuinely routine.

Splits the two: a missing file stays a silent, named expected (routine,
the exact case this method's repair path exists for), while any other
I/O error now logs via the same LOG.warnv pattern already used
elsewhere in this class for a safe-to-continue failure, since an
existing file that can't be read for some other reason is worth a
record even though the safe response is still the same repair write.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-30 23:29:45 -05:00
1 parent ea41b775aa
commit 4f2f494442
2 files changed
+70 -4

No files matched your search

@@ -1003,12 +1003,19 @@ public class CodeArtifactService implements Resettable {
digest.update(buffer, 0, read);
}
return expectedSha256.equalsIgnoreCase(SigV4RequestValidator.hexEncode(digest.digest()));
} catch (NoSuchFileException e) {
} catch (NoSuchFileException expected) {
// Routine, not diagnostically interesting: the metadata already confirmed this asset
// exists (the only way this method gets called), so a missing file here means something
// touched the asset store directly without going through Floci, e.g. a partial restore
// that skipped it. That is exactly the case this method's caller repairs, not a real
// failure worth a log line.
return false;
} catch (IOException e) {
// Any I/O error reading the existing file (not just a clean "not found") reads the
// same as "can't confirm it's intact": a repair write is the safe response, not a
// thrown exception that would turn an otherwise-successful idempotent retry into one.
// Unlike a missing file, any other I/O error reading an existing file is unexpected and
// worth keeping a record of, even though the safe response is still the same: a repair
// write, not a thrown exception that would turn an otherwise-successful idempotent
// retry into one.
LOG.warnv(e, "Could not verify existing CodeArtifact asset file {0}: {1}", filePath, e.getMessage());
return false;
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("JVM does not support SHA-256", e);