exif: Renamed ErrNotExif to ErrNoExif.

This commit is contained in:
Dustin Oprea 2018-06-13 05:51:28 -04:00
parent dcd8d23b07
commit 235b1a5936
3 changed files with 13 additions and 9 deletions

12
exif.go
View File

@ -52,7 +52,7 @@ var (
)
var (
ErrNotExif = errors.New("not exif data")
ErrNoExif = errors.New("no exif data")
ErrExifHeaderError = errors.New("exif header error")
)
@ -76,13 +76,13 @@ func SearchAndExtractExif(data []byte) (rawExif []byte, err error) {
if _, err := ParseExifHeader(data[i:]); err == nil {
foundAt = i
break
} else if log.Is(err, ErrNotExif) == false {
} else if log.Is(err, ErrNoExif) == false {
log.Panic(err)
}
}
if foundAt == -1 {
log.Panicf("EXIF start not found")
log.Panic(ErrNoExif)
}
return data[foundAt:], nil
@ -127,7 +127,7 @@ func (eh ExifHeader) String() string {
// ParseExifHeader parses the bytes at the very top of the header.
//
// This will panic with ErrNotExif on any data errors so that we can double as
// This will panic with ErrNoExif on any data errors so that we can double as
// an EXIF-detection routine.
func ParseExifHeader(data []byte) (eh ExifHeader, err error) {
defer func() {
@ -146,14 +146,14 @@ func ParseExifHeader(data []byte) (eh ExifHeader, err error) {
byteOrder, found := ByteOrderLookup[byteOrderBytes]
if found == false {
exifLogger.Warningf(nil, "EXIF byte-order not recognized: [%v]", byteOrderBytes)
log.Panic(ErrNotExif)
log.Panic(ErrNoExif)
}
fixedBytes := [2]byte { data[2], data[3] }
expectedFixedBytes := ExifFixedBytesLookup[byteOrder]
if fixedBytes != expectedFixedBytes {
exifLogger.Warningf(nil, "EXIF header fixed-bytes should be [%v] but are: [%v]", expectedFixedBytes, fixedBytes)
log.Panic(ErrNotExif)
log.Panic(ErrNoExif)
}
firstIfdOffset := byteOrder.Uint32(data[4:8])

View File

@ -42,7 +42,7 @@ func TestVisit(t *testing.T) {
if _, err := ParseExifHeader(data[i:]); err == nil {
foundAt = i
break
} else if log.Is(err, ErrNotExif) == false {
} else if log.Is(err, ErrNoExif) == false {
log.Panic(err)
}
}

View File

@ -1175,6 +1175,8 @@ func FindIfdFromRootIfd(rootIfd *Ifd, ifdDesignation string) (ifd *Ifd, err erro
case "ifd0":
// We're already on it.
return ifd, nil
case "ifd1":
if ifd.NextIfd == nil {
log.Panicf("IFD1 not found")
@ -1205,10 +1207,12 @@ func FindIfdFromRootIfd(rootIfd *Ifd, ifdDesignation string) (ifd *Ifd, err erro
}
candidates := make([]string, len(IfdDesignations))
i := 0
for key, _ := range IfdDesignations {
candidates = append(candidates, key)
candidates[i] = key
i++
}
log.Panicf("IFD designation not valid. Use: %s\n", strings.Join(candidates, ", "))
log.Panicf("IFD designation [%s] not valid. Use: %s\n", ifdDesignation, strings.Join(candidates, ", "))
return nil, nil
}