compare's exit code is always 0

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
benze
Posts: 5
Joined: 2013-09-07T18:35:10-07:00
Authentication code: 6789

Re: compare's exit code is always 0

Post by benze »

magick wrote: We'll keep the exiting exit status for all ImageMagick utilities except the compare utility. For it, we will return the same exit status as grep. That is if the images are similar and no errors, return 0. If the images are dissimilar and no errors, return 1. If an error occurs, return 1.
I don't understand. Part of the idea of the exit code is to be able to determine if there was an error or not. But here the suggestion is to make the utility return the same error code in the case of a success and an error. In both cases, whether the images are different or an error was thrown, return 1. But that does not tell the user or the calling utility if an error was thrown or if the two images are just different. Consequently, there is no way to know if the result can be "trusted". ie: did the utility complete properly and the images are indeed different, or was there an error in the process and the utility crashed (ex: file does not exist, file access errors, etc). Consequently, a non-zero exit code ends up not meaning anything at all.

At the very least, I would expect a different exit code on error vs on difference of images (ex: 0 if images are the same, 1 if images are different, and something >1 on error depending on the error).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compare's exit code is always 0

Post by fmw42 »

I think the idea is to use the -dissimilarity-threshold, so that if the images are too dissimilar, compare will exit with a message and give error code 1. So if you believe that some similarity value (say rmse) is too high then if that value is found, it will quit with the message and error 1. If you want it to run to completion no matter what the similarity (rmse) value is, then always include -dissimilarity-threshold 1 and it will never quit unless there is some real error and not just too dissimilar.

The IM developers can correct me on this if I misunderstand.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: compare's exit code is always 0

Post by dlemstra »

I believe the 'If an error occurs, return 1' is a typo and should be ' If an error occurs, return 2'. This is what grep is doing.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: compare's exit code is always 0

Post by magick »

We'll keep the existing exit status for all ImageMagick utilities except the compare utility. For it, we will return the same exit status as grep. That is if the images are similar and no errors, return 0. If the images are dissimilar and no errors, return 1. If an error occurs, return 2.

Are we good to go? If so, we'll get it coded over the next few days.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: compare's exit code is always 0

Post by fmw42 »

What determines if "similar"? Does it have to be perfect? Or are you going to use the -dissimilarity-threshold value as the determining factor? If so, won't it quit before finishing, if the values are too dissimilar.
bigmontana
Posts: 1
Joined: 2014-10-24T22:06:43-07:00
Authentication code: 6789

Re: compare's exit code is always 0

Post by bigmontana »

Please reconsider changing your convention. Capturing the return value from stderr is a pain in the arse.
Post Reply