mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
👌 Improved error handling
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Cocoa
|
||||
|
||||
class ValetServicesManager: ServicesManager {
|
||||
override init() {
|
||||
@ -98,7 +99,14 @@ class ValetServicesManager: ServicesManager {
|
||||
return service.name == named
|
||||
}
|
||||
|
||||
let action = wrapper.status == .active ? "stop" : "start"
|
||||
// Normally, we allow starting and stopping
|
||||
var action = wrapper.status == .active ? "stop" : "start"
|
||||
|
||||
// However, if we've encountered an error, attempt to restart
|
||||
if wrapper.status == .error {
|
||||
action = "restart"
|
||||
}
|
||||
|
||||
let command = "services \(action) \(wrapper.formula.name)"
|
||||
|
||||
// Run the command
|
||||
@ -107,19 +115,46 @@ class ValetServicesManager: ServicesManager {
|
||||
// Reload the services status to confirm this worked
|
||||
await ServicesManager.shared.reloadServicesStatus()
|
||||
|
||||
Task {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func presentTroubleshootingForService(named: String) {
|
||||
Task { @MainActor in
|
||||
let after = self.homebrewServices.first { service in
|
||||
return service.name == named
|
||||
}
|
||||
|
||||
guard let before else { return }
|
||||
guard let after else { return }
|
||||
|
||||
if before.running == after.running {
|
||||
// The status has not changed, report this to the user
|
||||
Log.err("The service '\(named)' status has not changed. Its status is: \(after.status ?? "empty")")
|
||||
} else {
|
||||
Log.info("The service '\(named)' has been successfully toggled.")
|
||||
if after.status == "error" {
|
||||
Log.err("The service '\(named)' is now reporting an error.")
|
||||
|
||||
let hasErrorPath = after.error_log_path != nil
|
||||
|
||||
if hasErrorPath {
|
||||
BetterAlert().withInformation(
|
||||
title: "alert.service_error.title".localized(named),
|
||||
subtitle: "alert.service_error.subtitle.error_log".localized(named),
|
||||
description: "alert.service_error.extra".localized
|
||||
)
|
||||
.withPrimary(text: "alert.service_error.button.close".localized)
|
||||
.withSecondary(text: "alert.service_error.button.show_log", action: { alert in
|
||||
let url = URL(fileURLWithPath: after.error_log_path!)
|
||||
NSWorkspace.shared.activateFileViewerSelecting([url])
|
||||
alert.close(with: .OK)
|
||||
})
|
||||
.show()
|
||||
} else {
|
||||
BetterAlert().withInformation(
|
||||
title: "alert.service_error.title".localized(named),
|
||||
subtitle: "alert.service_error.subtitle.no_error_log".localized(named),
|
||||
description: "alert.service_error.extra".localized
|
||||
)
|
||||
.withPrimary(text: "alert.service_error.button.close".localized)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ struct HelpButton: View {
|
||||
Button(action: action, label: {
|
||||
Text("?").font(.system(size: 12, weight: .medium))
|
||||
})
|
||||
.focusable(false)
|
||||
}
|
||||
|
||||
struct HelpButton_Previews: PreviewProvider {
|
||||
|
@ -12,25 +12,22 @@ import SwiftUI
|
||||
struct ServicesView: View {
|
||||
|
||||
static func asMenuItem(perRow: Int = 4) -> NSMenuItem {
|
||||
let item = NSMenuItem()
|
||||
let view = {
|
||||
let rootView = Self(manager: ServicesManager.shared, perRow: perRow)
|
||||
let view = NSHostingView(rootView: rootView)
|
||||
view.autoresizingMask = [.width]
|
||||
view.setFrameSize(CGSize(width: view.frame.width, height: rootView.height))
|
||||
view.focusRingType = .none
|
||||
return view
|
||||
}()
|
||||
|
||||
let manager = ServicesManager.shared
|
||||
let menuItem = {
|
||||
let item = NSMenuItem()
|
||||
item.view = view
|
||||
return item
|
||||
}()
|
||||
|
||||
let rootView = Self(
|
||||
manager: manager,
|
||||
perRow: perRow
|
||||
)
|
||||
|
||||
let view = NSHostingView(rootView: rootView)
|
||||
view.autoresizingMask = [.width]
|
||||
view.setFrameSize(
|
||||
CGSize(width: view.frame.width, height: rootView.height)
|
||||
)
|
||||
// view.layer?.backgroundColor = CGColor.init(red: 255, green: 0, blue: 0, alpha: 1)
|
||||
view.focusRingType = .none
|
||||
|
||||
item.view = view
|
||||
return item
|
||||
return menuItem
|
||||
}
|
||||
|
||||
@ObservedObject var manager: ServicesManager
|
||||
|
@ -448,6 +448,15 @@ You can do this by running `composer global update` in your terminal. After that
|
||||
"alert.php_switch_unavailable.info" = "Please make sure PHP %@ is installed and you can switch to it in the dropdown. Currently supported versions include PHP: %@.";
|
||||
"alert.php_switch_unavailable.ok" = "OK";
|
||||
|
||||
// Service error
|
||||
"alert.service_error.title" = "The service '%@' is reporting an error!";
|
||||
"alert.service_error.subtitle.error_log" = "This means that the service '%@' isn't running. This may prevent Valet from working correctly. This service has an associated log file that you might want to check, however.";
|
||||
"alert.service_error.subtitle.no_error_log" = "This means that the service '%@' isn't running. This may prevent Valet from working correctly. Unfortunately, there is no associated log file for this service.";
|
||||
"alert.service_error.extra" = "You may also wish to follow common troubleshooting steps. To learn more, press the '?' button in the services section in PHP Monitor.";
|
||||
|
||||
"alert.service_error.button.show_log" = "View Error Log";
|
||||
"alert.service_error.button.close" = "Close";
|
||||
|
||||
// Composer issues
|
||||
"alert.global_composer_platform_issues.title" = "Composer detected issues in your platform";
|
||||
"alert.global_composer_platform_issues.subtitle" = "The version of PHP you switched to is too old for the global Composer dependencies you have installed. These dependencies will need to be updated.";
|
||||
|
Reference in New Issue
Block a user