Skip to content

Commit

Permalink
Merge pull request #136 from nlnwa/fix/validate-panic
Browse files Browse the repository at this point in the history
fix: validate panics if record with error
  • Loading branch information
maeb authored May 15, 2024
2 parents e0de5be + e6c813f commit 64cc03e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 5 additions & 3 deletions cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,18 @@ func validateFile(fileSystem afero.Fs, file string) filewalker.Result {
if err == io.EOF {
break
}
if warcRecord.Type() == gowarc.Warcinfo {
warcInfoId = warcRecord.WarcHeader().GetId(gowarc.WarcRecordID)
}

result.IncrRecords()
result.IncrProcessed()
if err != nil {
result.AddError(fmt.Errorf("rec num: %d, offset: %d, cause: %w", result.Records(), currentOffset, err))
break
}

if warcRecord.Type() == gowarc.Warcinfo {
warcInfoId = warcRecord.WarcHeader().GetId(gowarc.WarcRecordID)
}

err = warcRecord.ValidateDigest(validation)
if err != nil {
result.AddError(fmt.Errorf("rec num: %d, offset: %d, cause: %w", result.Records(), currentOffset, err))
Expand Down
5 changes: 0 additions & 5 deletions cmd/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,5 @@ import (
func TestValidateSamsungFileWithError(t *testing.T) {
testDataDir := filepath.Join("..", "..", "testdata")
warcWithErrors := filepath.Join(testDataDir, "samsung-with-error", "rec-33318048d933-20240317162652059-0.warc.gz")
defer func() {
if r := recover(); r == nil {
t.Errorf("validateFile did not panic")
}
}()
_ = validateFile(afero.NewOsFs(), warcWithErrors)
}

0 comments on commit 64cc03e

Please sign in to comment.