1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-12-21 11:10:08 +01:00

🐛 Improve robustness of boot procedure

- Added extra check for valid `brew info php --json` output
- Moved PHP binary check and PHP installation not broken checks to `core`
- Workaround for Homebrew logs appearing in JSON output
This commit is contained in:
2025-11-10 12:36:22 +01:00
parent b4cda15920
commit 1994e1fa84
4 changed files with 58 additions and 17 deletions

View File

@@ -3920,7 +3920,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1690; CURRENT_PROJECT_VERSION = 1695;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG = YES; DEBUG = YES;
ENABLE_APP_SANDBOX = NO; ENABLE_APP_SANDBOX = NO;
@@ -3939,7 +3939,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.5; MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 25.10.1; MARKETING_VERSION = 25.10.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@@ -3964,7 +3964,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1690; CURRENT_PROJECT_VERSION = 1695;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG = NO; DEBUG = NO;
ENABLE_APP_SANDBOX = NO; ENABLE_APP_SANDBOX = NO;
@@ -3983,7 +3983,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.5; MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 25.10.1; MARKETING_VERSION = 25.10.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon;
PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
@@ -4146,7 +4146,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1690; CURRENT_PROJECT_VERSION = 1695;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG = YES; DEBUG = YES;
ENABLE_APP_SANDBOX = NO; ENABLE_APP_SANDBOX = NO;
@@ -4165,7 +4165,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.5; MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 25.10.1; MARKETING_VERSION = 25.10.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap;
PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME) EAP"; PRODUCT_NAME = "$(TARGET_NAME) EAP";
@@ -4339,7 +4339,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1690; CURRENT_PROJECT_VERSION = 1695;
DEAD_CODE_STRIPPING = YES; DEAD_CODE_STRIPPING = YES;
DEBUG = NO; DEBUG = NO;
ENABLE_APP_SANDBOX = NO; ENABLE_APP_SANDBOX = NO;
@@ -4358,7 +4358,7 @@
"@executable_path/../Frameworks", "@executable_path/../Frameworks",
); );
MACOSX_DEPLOYMENT_TARGET = 13.5; MACOSX_DEPLOYMENT_TARGET = 13.5;
MARKETING_VERSION = 25.10.1; MARKETING_VERSION = 25.10.2;
PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon.eap;
PRODUCT_MODULE_NAME = PHP_Monitor; PRODUCT_MODULE_NAME = PHP_Monitor;
PRODUCT_NAME = "$(TARGET_NAME) EAP"; PRODUCT_NAME = "$(TARGET_NAME) EAP";

View File

@@ -22,16 +22,39 @@ class PhpEnvironments {
} }
/** /**
Determine which PHP version the `php` formula is aliased to. Loads the valid HomebrewPackage information.
If invalid, this will prevent PHP Monitor from starting correctly.
*/ */
@MainActor func determinePhpAlias() async { func getHomebrewInformation() async {
let brewPhpAlias = await container.shell.pipe("\(container.paths.brew) info php --json").out let brewPhpAlias = await container.shell.pipe("\(container.paths.brew) info php --json").out
self.homebrewPackage = try! JSONDecoder().decode( // Remove any non-JSON output (progress indicators, etc.) before the actual JSON array
[HomebrewPackage].self, // This is a workaround for https://github.com/homebrew/brew/issues/20978
from: brewPhpAlias.data(using: .utf8)! // Since users may not upgrade Homebrew frequently, this fix will remain
).first! let jsonString = brewPhpAlias
.components(separatedBy: .newlines)
.drop(while: { !$0.trimmingCharacters(in: .whitespaces).hasPrefix("[") })
.joined(separator: "\n")
// Get all packages
let packages = try? JSONDecoder().decode(
[HomebrewPackage].self,
from: jsonString.data(using: .utf8)!
)
// But we only need the first one!
guard let package = packages?.first else {
Log.err("Could not determine PHP version due to malformed output.")
return
}
self.homebrewPackage = package
}
/**
Determine which PHP version the `php` formula is aliased to.
*/
func determinePhpAlias() async {
PhpEnvironments.brewPhpAlias = self.homebrewPackage.version PhpEnvironments.brewPhpAlias = self.homebrewPackage.version
Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version).") Log.info("[BREW] On your system, the `php` formula means version \(homebrewPackage.version).")

View File

@@ -118,9 +118,7 @@ class Startup {
App.shared.container.paths.optPath App.shared.container.paths.optPath
), ),
descriptionText: "startup.errors.php_opt.desc".localized descriptionText: "startup.errors.php_opt.desc".localized
) ),
]),
EnvironmentCheckGroup(name: "valet", condition: { return Valet.installed }, checks: [
// ================================================================================= // =================================================================================
// The PHP binary must exist. // The PHP binary must exist.
// ================================================================================= // =================================================================================
@@ -148,6 +146,21 @@ class Startup {
), ),
descriptionText: "startup.errors.dyld_library.desc".localized descriptionText: "startup.errors.dyld_library.desc".localized
), ),
// =================================================================================
// Make sure we can get valid output from Homebrew's info command.
// =================================================================================
EnvironmentCheck(
command: { container in
await container.phpEnvs.getHomebrewInformation()
return container.phpEnvs.homebrewPackage == nil
},
name: "`brew info php --json` could parse valid JSON",
titleText: "startup.errors.php_brew_info_invalid.title".localized,
subtitleText: "startup.errors.php_brew_info_invalid.subtitle".localized,
descriptionText: "startup.errors.php_brew_info_invalid.desc".localized
)
]),
EnvironmentCheckGroup(name: "valet", condition: { return Valet.installed }, checks: [
// ================================================================================= // =================================================================================
// The Valet binary must exist. // The Valet binary must exist.
// ================================================================================= // =================================================================================

View File

@@ -671,6 +671,11 @@ You can do this by running `composer global update` in your terminal. After that
"startup.errors.php_binary.subtitle" = "You must install PHP via Homebrew. The app will not work correctly until you resolve this issue."; "startup.errors.php_binary.subtitle" = "You must install PHP via Homebrew. The app will not work correctly until you resolve this issue.";
"startup.errors.php_binary.desc" = "Usually running `brew link php` in your Terminal will resolve this issue.\n\nTo diagnose what is wrong, you can try running `which php` in your Terminal, it should return `%@`."; "startup.errors.php_binary.desc" = "Usually running `brew link php` in your Terminal will resolve this issue.\n\nTo diagnose what is wrong, you can try running `which php` in your Terminal, it should return `%@`.";
// Invalid brew info php output
"startup.errors.php_brew_info_invalid.title" = "Homebrew returned invalid output for `brew info php --json` which requires valid JSON as output.";
"startup.errors.php_brew_info_invalid.subtitle" = "This will prevent PHP Monitor from starting correctly. It's possible that Homebrew is currently in a broken state or some additional logging crept into the output of this command. This is a known issue.";
"startup.errors.php_brew_info_invalid.desc" = "Simply retrying may fix the issue, but you may want to run the command yourself if the issue persists and validate if it's valid JSON. Press OK, and select Retry to try again.";
// PHP not found in /usr/local/opt or /opt/homebrew/opt // PHP not found in /usr/local/opt or /opt/homebrew/opt
"startup.errors.php_opt.title" = "PHP is not correctly installed"; "startup.errors.php_opt.title" = "PHP is not correctly installed";
"startup.errors.php_opt.subtitle" = "The PHP alias was not found in `%@`. The app will not work correctly until you resolve this issue."; "startup.errors.php_opt.subtitle" = "The PHP alias was not found in `%@`. The app will not work correctly until you resolve this issue.";