ExifTool Forum

ExifTool => Developers => Topic started by: Hayo Baan on April 13, 2019, 07:29:33 AM

Title: Adding warnings from within a custom tag
Post by: Hayo Baan on April 13, 2019, 07:29:33 AM
Hi Phil,

I'd like to be able to add warnings when inside a custom tag (e.g. in the printconv or valueconv code) . Is this possible and if possible, how do I do so in the most elegant way?

Thanks,
Hayo
Title: Re: Adding warnings from within a custom tag
Post by: Phil Harvey on April 15, 2019, 07:26:23 AM
Hi Hayo,

This is a bit tricky.  In general, warnings should be generated before the ValueConv because by this time the calling program already has a list of tags that have been extracted.  So even though you generate a new warning tag, it may not be noticed.  It will work from a RawConv, but at that point  you only have access to the raw values of the other tags via @raw.  To generate a warning, do this:

$self->Warn("some warning");

Only in the case when no tags were extracted does the exiftool application go back to check the warnings for a second time.  So in this case a warning in the ValueConv would be shown.

- Phil
Title: Re: Adding warnings from within a custom tag
Post by: Hayo Baan on April 15, 2019, 09:28:43 AM
Hmm, it's a pity I can really only add warnings in rawconv. For this particular instance it does not matter; I want to provide a tag that always returns the three letter ISO country code even if the two letter country code was used (in this case I want the warning to be shown). This I can do in rawconv too, but in other cases it would be nice to be able to add warnings in e.g. valueconv.
Title: Re: Adding warnings from within a custom tag
Post by: Phil Harvey on April 15, 2019, 10:37:11 AM
BTW, the complete documentation for stuff like this is here (https://github.com/exiftool/exiftool/blob/master/lib/Image/ExifTool/README), which says this in the RawConv description:

                  RawConv may generate Warning or Error tags, while
                  ValueConv and PrintConv should not (see ValueConv note below).

with this note in the ValueConv documentation:

                  Note:  Warnings issued by these conversions are intercepted by
                  ExifTool and saved as Warning tags, but since ValueConv and
                  PrintConv conversions are done on demand, the warnings may be
                  generated after the list of extracted tags is returned, so may
                  easily be missed.

I have thought about this a bit more, but I can't see an easy way around this.

- Phil
Title: Re: Adding warnings from within a custom tag
Post by: Hayo Baan on April 15, 2019, 11:04:40 AM
OK, I can live with not having this ;D

Thanks for the link with the full info. It's so easy to overlook the part where things are documented...