Skip to content

Commit

Permalink
don't throw fatalError, throw instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Sep 9, 2024
1 parent f92b767 commit 45a17aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct DeviceInfoHandler: HTTPHandler {
let springboardApp = XCUIApplication(bundleIdentifier: springboardBundleId)
let screenSize = springboardApp.frame.size

let (width, height) = ScreenSizeHelper.actualScreenSize()
let (width, height) = try ScreenSizeHelper.actualScreenSize()
let deviceInfo = DeviceInfoResponse(
widthPoints: Int(width),
heightPoints: Int(height),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ struct ScreenSizeHelper {
}

/// Takes device orientation into account.
static func actualScreenSize() -> (Float, Float) {
static func actualScreenSize() throws -> (Float, Float) {
let orientation = XCUIDevice.shared.orientation

let (width, height) = physicalScreenSize()
let (actualWidth, actualHeight) = switch (orientation) {
case .portrait, .portraitUpsideDown: (width, height)
case .landscapeLeft, .landscapeRight: (height, width)
case .faceDown, .faceUp, .unknown: fatalError("Unsupported orientation: \(orientation)")
@unknown default: fatalError("Unsupported orientation: \(orientation)")
case .faceDown, .faceUp, .unknown: throw AppError(message: "Unsupported orientation: \(orientation)")
@unknown default: throw AppError(message: "Unsupported orientation: \(orientation)")
}

return (actualWidth, actualHeight)
Expand Down

0 comments on commit 45a17aa

Please sign in to comment.