mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-07 13:20:05 +01:00
👌 Improved error handling
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
class ValetServicesManager: ServicesManager {
|
class ValetServicesManager: ServicesManager {
|
||||||
override init() {
|
override init() {
|
||||||
@@ -98,7 +99,14 @@ class ValetServicesManager: ServicesManager {
|
|||||||
return service.name == named
|
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)"
|
let command = "services \(action) \(wrapper.formula.name)"
|
||||||
|
|
||||||
// Run the command
|
// Run the command
|
||||||
@@ -107,19 +115,46 @@ class ValetServicesManager: ServicesManager {
|
|||||||
// Reload the services status to confirm this worked
|
// Reload the services status to confirm this worked
|
||||||
await ServicesManager.shared.reloadServicesStatus()
|
await ServicesManager.shared.reloadServicesStatus()
|
||||||
|
|
||||||
|
Task {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func presentTroubleshootingForService(named: String) {
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
let after = self.homebrewServices.first { service in
|
let after = self.homebrewServices.first { service in
|
||||||
return service.name == named
|
return service.name == named
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let before else { return }
|
|
||||||
guard let after else { return }
|
guard let after else { return }
|
||||||
|
|
||||||
if before.running == after.running {
|
if after.status == "error" {
|
||||||
// The status has not changed, report this to the user
|
Log.err("The service '\(named)' is now reporting an error.")
|
||||||
Log.err("The service '\(named)' status has not changed. Its status is: \(after.status ?? "empty")")
|
|
||||||
|
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 {
|
} else {
|
||||||
Log.info("The service '\(named)' has been successfully toggled.")
|
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: {
|
Button(action: action, label: {
|
||||||
Text("?").font(.system(size: 12, weight: .medium))
|
Text("?").font(.system(size: 12, weight: .medium))
|
||||||
})
|
})
|
||||||
|
.focusable(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HelpButton_Previews: PreviewProvider {
|
struct HelpButton_Previews: PreviewProvider {
|
||||||
|
|||||||
@@ -12,25 +12,22 @@ import SwiftUI
|
|||||||
struct ServicesView: View {
|
struct ServicesView: View {
|
||||||
|
|
||||||
static func asMenuItem(perRow: Int = 4) -> NSMenuItem {
|
static func asMenuItem(perRow: Int = 4) -> NSMenuItem {
|
||||||
let item = NSMenuItem()
|
let view = {
|
||||||
|
let rootView = Self(manager: ServicesManager.shared, perRow: perRow)
|
||||||
let manager = ServicesManager.shared
|
|
||||||
|
|
||||||
let rootView = Self(
|
|
||||||
manager: manager,
|
|
||||||
perRow: perRow
|
|
||||||
)
|
|
||||||
|
|
||||||
let view = NSHostingView(rootView: rootView)
|
let view = NSHostingView(rootView: rootView)
|
||||||
view.autoresizingMask = [.width]
|
view.autoresizingMask = [.width]
|
||||||
view.setFrameSize(
|
view.setFrameSize(CGSize(width: view.frame.width, height: rootView.height))
|
||||||
CGSize(width: view.frame.width, height: rootView.height)
|
|
||||||
)
|
|
||||||
// view.layer?.backgroundColor = CGColor.init(red: 255, green: 0, blue: 0, alpha: 1)
|
|
||||||
view.focusRingType = .none
|
view.focusRingType = .none
|
||||||
|
return view
|
||||||
|
}()
|
||||||
|
|
||||||
|
let menuItem = {
|
||||||
|
let item = NSMenuItem()
|
||||||
item.view = view
|
item.view = view
|
||||||
return item
|
return item
|
||||||
|
}()
|
||||||
|
|
||||||
|
return menuItem
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObservedObject var manager: ServicesManager
|
@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.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";
|
"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
|
// Composer issues
|
||||||
"alert.global_composer_platform_issues.title" = "Composer detected issues in your platform";
|
"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.";
|
"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