@@ -84,7 +84,6 @@ func sendTelegramMessage(_ message: String, to chatID: Int, image: String? = nil
8484}
8585
8686func handleScreenshotError( entry: URLEntry ) throws {
87- print ( " Handling error. " )
8887 let errorFile = " \( directory ( for: entry) ) /error "
8988 // If the errorReportMinutes are not set, we immediately notify the user
9089 guard errorReportMinutes > 0 else {
@@ -143,15 +142,23 @@ func screenshotNCC(_ oldImage: String, _ latestImage: String, diffFile: String)
143142 diffFile
144143 ] , standardOutput: nccPipe, standardError: nccPipe)
145144
145+ let nccData = nccPipe. fileHandleForReading. readDataToEndOfFile ( )
146+ guard let nccString = String ( data: nccData, encoding: . utf8) else {
147+ return nil
148+ }
149+
150+ // If the images are different-sized, we don't need to treat this as an error.
151+ // Instead, we just notify the user about it by setting the NCC to 0
152+ if nccString. contains ( " compare: image widths or heights differ " ) {
153+ return 0
154+ }
155+
146156 // The compare command returns 0, if the images are similar, 1 if they are dissimilar and something else on an error
157+ // The error case of different sizes was already handled by the above statement
147158 if case . failure( let code) = result,
148159 code != 1 && code != 0 {
149160 return nil
150161 }
151162
152- let nccData = nccPipe. fileHandleForReading. readDataToEndOfFile ( )
153- guard let nccString = String ( data: nccData, encoding: . utf8) else {
154- return nil
155- }
156163 return Double ( nccString)
157164}
0 commit comments