pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.81k stars 583 forks source link

Occasionally getting error "SnapshotTesting/UIImage.swift:24: Fatal error: Unexpectedly found nil while unwrapping an Optional value" #613

Open simondelphia opened 2 years ago

simondelphia commented 2 years ago

Occasionally getting an error on CI

SnapshotTesting/UIImage.swift:24: Fatal error: Unexpectedly found nil while unwrapping an Optional value

This is referring to a line here: https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Sources/SnapshotTesting/Snapshotting/UIImage.swift

Which has some force unwraps.

I'm not sure why this is happening — possibly not even related to this repo.

But instead of force unwrapping and leading to a fatal error, this could presumably be handled more gracefully instead.

niemmi-gs commented 2 years ago

Hello @simondelphia, I got the same error, please check if *.png files are ok, in my case my was corrupted.

simondelphia commented 2 years ago

Yes they are corrupted. The cause of my issue has nothing to do with this library, so I didn't get into the details. Just would be nice if the library failed more gracefully.

nhaarman commented 1 year ago

@simondelphia But do you know how you resolved this issue?

KamilGucik commented 4 months ago

@nhaarman @simondelphia @niemmi-gs Check if you have lfs configured. In my case it was the reason of the problem. I had to install them on CI

simonbromberg commented 4 months ago

Yes iirc this was a case of something going wrong with git lfs. Git LFS was installed and working fine in most cases though. My point with raising this GitHub issue however was that the library ought not to force unwrap like this and instead should fail gracefully in this case.

I don't remember exactly what we did to fix it. I know at one point we were trying to set up Xcode Cloud and we might have seen this because the test bundle didn't actually have access to the bundled files without some special workarounds we had to implement. But I'm sure we also saw this in other cases where there was just some problem with loading some images occasionally. In some cases someone may have failed to properly commit the file, in other cases it might have just been a problem with the runner failing to properly download the image etc.