fix(snapshots): completely ignore unsupported entries instead of reporting them as ignored errors to avoid snapshot warnings (#4613)

This commit is contained in:
Jarek Kowalski
2025-05-29 06:53:50 -07:00
committed by GitHub
parent dc1be13d85
commit dc1342e117
2 changed files with 36 additions and 24 deletions

View File

@@ -930,6 +930,12 @@ func (u *Uploader) processSingle(
if errors.Is(entry.ErrorInfo(), fs.ErrUnknown) {
isIgnoredError = policyTree.EffectivePolicy().ErrorHandlingPolicy.IgnoreUnknownTypes.OrDefault(true)
// If unknown types are configured to be ignored, skip them completely without any error reporting
if isIgnoredError {
return nil
}
prefix = "unknown entry"
} else {
isIgnoredError = policyTree.EffectivePolicy().ErrorHandlingPolicy.IgnoreFileErrors.OrDefault(false)

View File

@@ -426,10 +426,6 @@ func TestUpload_SubDirectoryReadFailureFailFast(t *testing.T) {
})
}
func objectIDsEqual(o1, o2 object.ID) bool {
return reflect.DeepEqual(o1, o2)
}
func TestUpload_SubDirectoryReadFailureIgnoredNoFailFast(t *testing.T) {
ctx := testlogging.Context(t)
th := newUploadTestHarness(ctx, t)
@@ -485,7 +481,7 @@ func TestUpload_ErrorEntries(t *testing.T) {
rootEntry: th.sourceDir,
ehp: policy.ErrorHandlingPolicy{},
wantFatalErrors: 2,
wantIgnoredErrors: 1,
wantIgnoredErrors: 0, // unknown entries are completely skipped when IgnoreUnknownTypes is true (default)
},
{
desc: "ignore both unknown types and other errors",
@@ -496,7 +492,7 @@ func TestUpload_ErrorEntries(t *testing.T) {
IgnoreUnknownTypes: &trueValue,
},
wantFatalErrors: 0,
wantIgnoredErrors: 3,
wantIgnoredErrors: 2, // only the two non-unknown errors are counted as ignored
},
{
desc: "ignore no errors",
@@ -518,7 +514,7 @@ func TestUpload_ErrorEntries(t *testing.T) {
IgnoreUnknownTypes: &trueValue,
},
wantFatalErrors: 2,
wantIgnoredErrors: 1,
wantIgnoredErrors: 0, // unknown entries are completely skipped when IgnoreUnknownTypes is true
},
{
desc: "ignore errors except unknown type errors",
@@ -546,15 +542,35 @@ func TestUpload_ErrorEntries(t *testing.T) {
t.Fatal(err)
}
verifyErrors(t, man, tc.wantFatalErrors, tc.wantIgnoredErrors, entryPathToError{
expectedErrors := entryPathToError{
"d1/some-failed-entry": errors.New("some-other-error"),
"d1/some-unknown-entry": errors.New("unknown or unsupported entry type"),
"d2/another-failed-entry": errors.New("another-error"),
})
}
// Only expect unknown entry in failed entries if IgnoreUnknownTypes is false
if tc.ehp.IgnoreUnknownTypes != nil && !tc.ehp.IgnoreUnknownTypes.OrDefault(true) {
expectedErrors["d1/some-unknown-entry"] = errors.New("unknown or unsupported entry type")
}
verifyErrors(t, man, tc.wantFatalErrors, tc.wantIgnoredErrors, expectedErrors)
})
}
}
func verifyErrors(t *testing.T, man *snapshot.Manifest, wantFatalErrors, wantIgnoredErrors int, wantErrors entryPathToError) {
t.Helper()
require.Equal(t, wantFatalErrors, man.RootEntry.DirSummary.FatalErrorCount, "invalid number of fatal errors")
require.Equal(t, wantIgnoredErrors, man.RootEntry.DirSummary.IgnoredErrorCount, "invalid number of ignored errors")
failedEntries := man.RootEntry.DirSummary.FailedEntries
for _, failedEntry := range failedEntries {
wantErr, ok := wantErrors[failedEntry.EntryPath]
require.True(t, ok, "expected error for entry path not found: %s", failedEntry.EntryPath)
require.Contains(t, failedEntry.Error, wantErr.Error())
}
}
func TestUpload_SubDirectoryReadFailureNoFailFast(t *testing.T) {
ctx := testlogging.Context(t)
th := newUploadTestHarness(ctx, t)
@@ -580,20 +596,6 @@ func TestUpload_SubDirectoryReadFailureNoFailFast(t *testing.T) {
})
}
func verifyErrors(t *testing.T, man *snapshot.Manifest, wantFatalErrors, wantIgnoredErrors int, wantErrors entryPathToError) {
t.Helper()
require.Equal(t, wantFatalErrors, man.RootEntry.DirSummary.FatalErrorCount, "invalid number of fatal errors")
require.Equal(t, wantIgnoredErrors, man.RootEntry.DirSummary.IgnoredErrorCount, "invalid number of ignored errors")
failedEntries := man.RootEntry.DirSummary.FailedEntries
for _, failedEntry := range failedEntries {
wantErr, ok := wantErrors[failedEntry.EntryPath]
require.True(t, ok, "expected error for entry path not found: %s", failedEntry.EntryPath)
require.Contains(t, failedEntry.Error, wantErr.Error())
}
}
func TestUpload_SubDirectoryReadFailureSomeIgnoredNoFailFast(t *testing.T) {
ctx := testlogging.Context(t)
th := newUploadTestHarness(ctx, t)
@@ -1736,3 +1738,7 @@ func verifyLogDetails(t *testing.T, desc string, wantDetailKeys []string, keysAn
sort.Strings(wantDetailKeys)
require.Equal(t, wantDetailKeys, gotDetailKeys, "invalid details for "+desc)
}
func objectIDsEqual(o1, o2 object.ID) bool {
return reflect.DeepEqual(o1, o2)
}