aboutsummaryrefslogtreecommitdiff
path: root/internal/extract
diff options
context:
space:
mode:
Diffstat (limited to 'internal/extract')
-rw-r--r--internal/extract/extract.go5
-rw-r--r--internal/extract/zipxml.go7
-rw-r--r--internal/extract/zipxml_test.go6
3 files changed, 14 insertions, 4 deletions
diff --git a/internal/extract/extract.go b/internal/extract/extract.go
index 7e3adec..0843c42 100644
--- a/internal/extract/extract.go
+++ b/internal/extract/extract.go
@@ -23,6 +23,11 @@ var (
// ErrUnsupported is returned when the format carries no text krino
// knows how to extract.
ErrUnsupported = errors.New("no text in this format")
+ // ErrPartial wraps the error of a document read only in part (an
+ // archive entry that would not open or parse). Text returns the text it
+ // did read along with it: a keyword found there is found, but one not
+ // found may be in the part that could not be read (plan 11).
+ ErrPartial = errors.New("part of it could not be read")
// ErrTooLarge is returned when the file is larger than the configured
// max-read; nothing is read in that case.
ErrTooLarge = errors.New("larger than max-read")
diff --git a/internal/extract/zipxml.go b/internal/extract/zipxml.go
index 1b3ba82..3b59d3a 100644
--- a/internal/extract/zipxml.go
+++ b/internal/extract/zipxml.go
@@ -102,8 +102,11 @@ func zipText(ctx context.Context, path, ext string, maxRead int64) (string, erro
}
b.WriteByte('\n')
}
- if !wroteText && firstErr != nil {
- return "", firstErr
+ if firstErr != nil {
+ if !wroteText {
+ return "", firstErr
+ }
+ return b.String(), fmt.Errorf("%w: %w", ErrPartial, firstErr)
}
return b.String(), nil
}
diff --git a/internal/extract/zipxml_test.go b/internal/extract/zipxml_test.go
index 14ead80..30a4cf9 100644
--- a/internal/extract/zipxml_test.go
+++ b/internal/extract/zipxml_test.go
@@ -138,8 +138,10 @@ func TestZipLenientOnMalformedEntry(t *testing.T) {
"word/document.xml": `<w:document xmlns:w="w"><w:body><w:p><w:r><w:t>good body text</w:t></w:r></w:p></w:body></w:document>`,
"word/footer1.xml": `<w:ftr xmlns:w="w"><w:p><w:r><w:t>broken</w:t></w:r></w:p></w:xyz>`,
}), 0)
- if err != nil {
- t.Fatalf("good entry alongside a malformed one: %v", err)
+ // Partly read: the text is kept, and ErrPartial says some of it is
+ // missing, so a keyword not found in it is unknown (plan 11).
+ if !errors.Is(err, ErrPartial) {
+ t.Fatalf("good entry alongside a malformed one: err %v, want ErrPartial", err)
}
if !strings.Contains(got, "good body text") {
t.Errorf("text from the good entry was discarded: %q", got)