From cc316fb4407dc6b138ec79915c6d399cbef8f756 Mon Sep 17 00:00:00 2001 From: Dustin Oprea Date: Sat, 2 May 2020 17:10:36 -0400 Subject: [PATCH] ifd_enumerate.go: (*Ifd).PrintTagTree() no longer fails on parseable undefined values https://github.com/dsoprea/go-exif/issues/33 --- v2/ifd_enumerate.go | 13 ++++++++++++- v2/ifd_tag_entry.go | 2 ++ v2/undefined/type.go | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/v2/ifd_enumerate.go b/v2/ifd_enumerate.go index 3c8a7fc..c02cbf5 100644 --- a/v2/ifd_enumerate.go +++ b/v2/ifd_enumerate.go @@ -13,6 +13,7 @@ import ( "github.com/dsoprea/go-logging" "github.com/dsoprea/go-exif/v2/common" + "github.com/dsoprea/go-exif/v2/undefined" ) var ( @@ -557,7 +558,17 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo var err error valuePhrase, err = ite.Format() - log.PanicIf(err) + if err != nil { + if log.Is(err, exifcommon.ErrUnhandledUndefinedTypedTag) == true { + ifdEnumerateLogger.Warningf(nil, "Skipping non-standard undefined tag: [%s] (%04x)", ifd.IfdPath, ite.TagId()) + continue + } else if err == exifundefined.ErrUnparseableValue { + ifdEnumerateLogger.Warningf(nil, "Skipping unparseable undefined tag: [%s] (%04x) [%s]", ifd.IfdPath, ite.TagId(), it.Name) + continue + } + + log.Panic(err) + } } else { valuePhrase = "!UNRESOLVED" } diff --git a/v2/ifd_tag_entry.go b/v2/ifd_tag_entry.go index 21273fa..1037271 100644 --- a/v2/ifd_tag_entry.go +++ b/v2/ifd_tag_entry.go @@ -178,6 +178,8 @@ func (ite *IfdTagEntry) Format() (phrase string, err error) { if err != nil { if err == exifcommon.ErrUnhandledUndefinedTypedTag { return exifundefined.UnparseableUnknownTagValuePlaceholder, nil + } else if err == exifundefined.ErrUnparseableValue { + return exifundefined.UnparseableHandledTagValuePlaceholder, nil } log.Panic(err) diff --git a/v2/undefined/type.go b/v2/undefined/type.go index c87fbf8..5e55e4c 100644 --- a/v2/undefined/type.go +++ b/v2/undefined/type.go @@ -9,10 +9,18 @@ import ( ) const ( + // UnparseableUnknownTagValuePlaceholder is the string to use for an unknown + // undefined tag. UnparseableUnknownTagValuePlaceholder = "!UNKNOWN" + + // UnparseableHandledTagValuePlaceholder is the string to use for a known + // value that is not parseable. + UnparseableHandledTagValuePlaceholder = "!MALFORMED" ) var ( + // ErrUnparseableValue is the error for a value that we should have been + // able to parse but were not able to. ErrUnparseableValue = errors.New("unparseable undefined tag") ) @@ -22,6 +30,8 @@ type UndefinedValueEncoder interface { Encode(value interface{}, byteOrder binary.ByteOrder) (encoded []byte, unitCount uint32, err error) } +// EncodeableValue wraps a value with the information that will be needed to re- +// encode it later. type EncodeableValue interface { EncoderName() string String() string