factor error code

This commit is contained in:
Celogeek 2023-04-25 21:41:19 +02:00
parent 01d1670edd
commit 8a1eeb400d
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
2 changed files with 7 additions and 4 deletions

View File

@ -172,7 +172,7 @@ func LoadImages(o *Options) ([]*epubimage.Image, error) {
bar.Close()
if len(images) == 0 {
return nil, fmt.Errorf("image not found")
return nil, errNoImagesFound
}
return images, nil

View File

@ -3,6 +3,7 @@ package epubimageprocessing
import (
"archive/zip"
"bytes"
"errors"
"fmt"
"io"
"io/fs"
@ -27,6 +28,8 @@ type Options struct {
Image *epubimage.Options
}
var errNoImagesFound = errors.New("no images found")
func (o *Options) mustExtractImage(imageOpener func() (io.ReadCloser, error)) *bytes.Buffer {
var b bytes.Buffer
if o.Dry {
@ -70,7 +73,7 @@ func (o *Options) loadDir() (totalImages int, output chan *tasks, err error) {
totalImages = len(images)
if totalImages == 0 {
err = fmt.Errorf("image not found")
err = errNoImagesFound
return
}
@ -115,7 +118,7 @@ func (o *Options) loadCbz() (totalImages int, output chan *tasks, err error) {
if totalImages == 0 {
r.Close()
err = fmt.Errorf("no images found")
err = errNoImagesFound
return
}
@ -176,7 +179,7 @@ func (o *Options) loadCbr() (totalImages int, output chan *tasks, err error) {
totalImages = len(names)
if totalImages == 0 {
err = fmt.Errorf("no images found")
err = errNoImagesFound
return
}