From 1ab1462c543f9fc756a5f983fb492cce122e8b52 Mon Sep 17 00:00:00 2001 From: Connor Neville Date: Tue, 18 Jun 2024 16:22:16 -0400 Subject: [PATCH] Replace force unwrap with fatalError, including more troubleshooting. --- Sources/SnapshotTesting/Snapshotting/UIImage.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/SnapshotTesting/Snapshotting/UIImage.swift b/Sources/SnapshotTesting/Snapshotting/UIImage.swift index 3d1bb5319..e8420e891 100644 --- a/Sources/SnapshotTesting/Snapshotting/UIImage.swift +++ b/Sources/SnapshotTesting/Snapshotting/UIImage.swift @@ -29,7 +29,14 @@ return Diffing( toData: { $0.pngData() ?? emptyImage().pngData()! }, - fromData: { UIImage(data: $0, scale: imageScale)! } + fromData: { + guard let image = UIImage(data: $0, scale: imageScale) else { + fatalError( + "Unable to load image from data on file for snapshot diffing. Check the contents of the image file. Projects using `git lfs` for file storage may need to run `git lfs pull`." + ) + } + return image + } ) { old, new in guard let message = compare(