Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
just log instead of fatal error
Browse files Browse the repository at this point in the history
  • Loading branch information
Monirzadeh committed Aug 19, 2023
1 parent 1c5c9c1 commit ca5c88f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions epub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ func unzipFile(sourceFilePath string, destDirPath string) error {
}
defer func() {
if err := r.Close(); err != nil {
log.Fatal(err)
log.Println(err)
}
}()

Expand All @@ -1095,7 +1095,7 @@ func unzipFile(sourceFilePath string, destDirPath string) error {
}
defer func() {
if err := rc.Close(); err != nil {
log.Fatal(err)
log.Println(err)
}
}()

Expand All @@ -1115,7 +1115,7 @@ func unzipFile(sourceFilePath string, destDirPath string) error {
}
defer func() {
if err := w.Close(); err != nil {
log.Fatal(err)
log.Println(err)
}
}()

Expand Down
20 changes: 10 additions & 10 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ func ExampleEpub_AddCSS() {
// Add CSS
css1Path, err := e.AddCSS("testdata/cover.css", "epub.css")
if err != nil {
log.Fatal(err)
log.Println(err)
}

// The filename is optional
css2Path, err := e.AddCSS("testdata/cover.css", "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

// Use the CSS in a section
Expand All @@ -43,13 +43,13 @@ func ExampleEpub_AddFont() {
// Add a font from a local file
font1Path, err := e.AddFont("testdata/redacted-script-regular.ttf", "font.ttf")
if err != nil {
log.Fatal(err)
log.Println(err)
}

// The filename is optional
font2Path, err := e.AddFont("testdata/redacted-script-regular.ttf", "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

fmt.Println(font1Path)
Expand All @@ -74,13 +74,13 @@ func ExampleEpub_AddImage() {
// Add an image from a local file
img1Path, err := e.AddImage("testdata/gophercolor16x16.png", "go-gopher.png")
if err != nil {
log.Fatal(err)
log.Println(err)
}

// Add an image from a URL. The filename is optional
img2Path, err := e.AddImage(testImageFromURLSource, "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

fmt.Println(img1Path)
Expand All @@ -99,7 +99,7 @@ func ExampleEpub_AddSection() {
<p>This is a paragraph.</p>`
section1Path, err := e.AddSection(section1Body, "Section 1", "firstsection.xhtml", "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

// Link to the first section
Expand All @@ -109,7 +109,7 @@ func ExampleEpub_AddSection() {
// The title and filename are also optional
section2Path, err := e.AddSection(section2Body, "", "", "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

fmt.Println(section1Path)
Expand All @@ -128,7 +128,7 @@ func ExampleEpub_AddSubSection() {
<p>This is a paragraph.</p>`
section1Path, err := e.AddSection(section1Body, "Section 1", "firstsection.xhtml", "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

// Link to the first section
Expand All @@ -138,7 +138,7 @@ func ExampleEpub_AddSubSection() {
// The title and filename are also optional
section2Path, err := e.AddSubSection(section1Path, section2Body, "", "", "")
if err != nil {
log.Fatal(err)
log.Println(err)
}

fmt.Println(section1Path)
Expand Down
9 changes: 4 additions & 5 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ func (e *Epub) writeEpub(rootEpubDir string, dst io.Writer) (int64, error) {
}
defer func() {
if err := r.Close(); err != nil {
log.Fatal(err)

log.Println(err)
}
}()

Expand All @@ -313,14 +312,14 @@ func (e *Epub) writeEpub(rootEpubDir string, dst io.Writer) (int64, error) {
mimetypeInfo, err := fs.Stat(filesystem, mimetypeFilePath)
if err != nil {
if err := z.Close(); err != nil {
log.Fatal(err)
log.Println(err)
}
return counter.Total, fmt.Errorf("unable to get FileInfo for mimetype file: %w", err)
}
err = addFileToZip(mimetypeFilePath, fileInfoToDirEntry(mimetypeInfo), nil)
if err != nil {
if err := z.Close(); err != nil {
log.Fatal(err)
log.Println(err)
}
return counter.Total, fmt.Errorf("unable to add mimetype file to EPUB: %w", err)
}
Expand All @@ -330,7 +329,7 @@ func (e *Epub) writeEpub(rootEpubDir string, dst io.Writer) (int64, error) {
err = fs.WalkDir(filesystem, rootEpubDir, addFileToZip)
if err != nil {
if err := z.Close(); err != nil {
log.Fatal(err)
log.Println(err)
}
return counter.Total, fmt.Errorf("unable to add file to EPUB: %w", err)
}
Expand Down

0 comments on commit ca5c88f

Please sign in to comment.