mirror of https://github.com/dsoprea/go-exif.git
exif.go: Just return ErrNoExif without panicking
- For well-defined, high-level errors we prefer to not wrap them with stacktraces if the stacktraces add little value. It just makes it more labor-intensive to handle those errors effectively (especially external ones).pull/18/head
parent
5b56a02e0a
commit
061c6b48d8
14
exif.go
14
exif.go
|
@ -79,12 +79,12 @@ func SearchAndExtractExif(data []byte) (rawExif []byte, err error) {
|
|||
foundAt = i
|
||||
break
|
||||
} else if log.Is(err, ErrNoExif) == false {
|
||||
log.Panic(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if foundAt == -1 {
|
||||
log.Panic(ErrNoExif)
|
||||
return nil, ErrNoExif
|
||||
}
|
||||
|
||||
return data[foundAt:], nil
|
||||
|
@ -144,7 +144,7 @@ func ParseExifHeader(data []byte) (eh ExifHeader, err error) {
|
|||
|
||||
if len(data) < 2 {
|
||||
exifLogger.Warningf(nil, "Not enough data for EXIF header (1): (%d)", len(data))
|
||||
log.Panic(ErrNoExif)
|
||||
return eh, ErrNoExif
|
||||
}
|
||||
|
||||
byteOrderBytes := [2]byte{data[0], data[1]}
|
||||
|
@ -152,24 +152,24 @@ 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(ErrNoExif)
|
||||
return eh, ErrNoExif
|
||||
}
|
||||
|
||||
if len(data) < 4 {
|
||||
exifLogger.Warningf(nil, "Not enough data for EXIF header (2): (%d)", len(data))
|
||||
log.Panic(ErrNoExif)
|
||||
return eh, 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(ErrNoExif)
|
||||
return eh, ErrNoExif
|
||||
}
|
||||
|
||||
if len(data) < 2 {
|
||||
exifLogger.Warningf(nil, "Not enough data for EXIF header (3): (%d)", len(data))
|
||||
log.Panic(ErrNoExif)
|
||||
return eh, ErrNoExif
|
||||
}
|
||||
|
||||
firstIfdOffset := byteOrder.Uint32(data[4:8])
|
||||
|
|
Loading…
Reference in New Issue