From 966033e052128a74ef1498d28c95321891c7914d Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 23 Mar 2023 17:44:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Prevent=20crash=20upon=20parsing?= =?UTF-8?q?=20invalid=20Valet=20directories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes #247, which can be caused when certain folders are not accessible for some reason. This can occur due to network reasons, but also because the linked folder in question is iCloud Drive. --- PHP Monitor.xcodeproj/project.pbxproj | 16 ++++++++-------- .../Valet/Scanners/ValetDomainScanner.swift | 14 +++++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 985dacc..287dea3 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -2889,7 +2889,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1077; + CURRENT_PROJECT_VERSION = 1078; DEAD_CODE_STRIPPING = YES; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; @@ -2902,7 +2902,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 5.8; + MARKETING_VERSION = 5.8.1; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -2919,7 +2919,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1077; + CURRENT_PROJECT_VERSION = 1078; DEAD_CODE_STRIPPING = YES; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; @@ -2932,7 +2932,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 5.8; + MARKETING_VERSION = 5.8.1; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3148,7 +3148,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1077; + CURRENT_PROJECT_VERSION = 1078; DEBUG = NO; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3160,7 +3160,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 5.8; + MARKETING_VERSION = 5.8.1; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev; PRODUCT_NAME = "$(TARGET_NAME) DEV"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3259,7 +3259,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 1077; + CURRENT_PROJECT_VERSION = 1078; DEBUG = YES; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; @@ -3271,7 +3271,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 5.8; + MARKETING_VERSION = 5.8.1; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.dev; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/phpmon/Domain/Integrations/Valet/Scanners/ValetDomainScanner.swift b/phpmon/Domain/Integrations/Valet/Scanners/ValetDomainScanner.swift index c8dcbf5..9a9a260 100644 --- a/phpmon/Domain/Integrations/Valet/Scanners/ValetDomainScanner.swift +++ b/phpmon/Domain/Integrations/Valet/Scanners/ValetDomainScanner.swift @@ -30,13 +30,17 @@ class ValetDomainScanner: DomainScanner { var sites: [ValetSite] = [] paths.forEach { path in - let entries = try! FileSystem - .getShallowContentsOfDirectory(path) + do { + let entries = try FileSystem + .getShallowContentsOfDirectory(path) - return entries.forEach { - if let site = self.resolveSite(path: "\(path)/\($0)") { - sites.append(site) + return entries.forEach { + if let site = self.resolveSite(path: "\(path)/\($0)") { + sites.append(site) + } } + } catch { + Log.err("Unexpected error getting contents of \(path): \(error).") } }