mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Display error notifications when config loading failed
This commit is contained in:
parent
bdd1bc2d86
commit
50b87e0240
1 changed files with 40 additions and 1 deletions
|
@ -1,15 +1,17 @@
|
||||||
package notifications
|
package notifications
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/safing/portbase/config"
|
||||||
"github.com/safing/portbase/modules"
|
"github.com/safing/portbase/modules"
|
||||||
)
|
)
|
||||||
|
|
||||||
var module *modules.Module
|
var module *modules.Module
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
module = modules.Register("notifications", prep, start, nil, "database", "base")
|
module = modules.Register("notifications", prep, start, nil, "database", "config", "base")
|
||||||
}
|
}
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
|
@ -22,6 +24,43 @@ func start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showConfigLoadingErrors()
|
||||||
|
|
||||||
go module.StartServiceWorker("cleaner", 1*time.Second, cleaner)
|
go module.StartServiceWorker("cleaner", 1*time.Second, cleaner)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func showConfigLoadingErrors() {
|
||||||
|
validationErrors := config.GetLoadedConfigValidationErrors()
|
||||||
|
if len(validationErrors) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger a module error for more awareness.
|
||||||
|
module.Error(
|
||||||
|
"config:validation-errors-on-load",
|
||||||
|
"Invalid Settings",
|
||||||
|
"Some current settings are invalid. Please update them and restart the Portmaster.",
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send one notification per invalid setting.
|
||||||
|
for _, validationError := range config.GetLoadedConfigValidationErrors() {
|
||||||
|
NotifyError(
|
||||||
|
fmt.Sprintf("config:validation-error:%s", validationError.Option.Key),
|
||||||
|
fmt.Sprintf("Invalid Setting for %s", validationError.Option.Name),
|
||||||
|
fmt.Sprintf(`Your current setting for %s is invalid: %s
|
||||||
|
|
||||||
|
Please update the setting and restart the Portmaster, until then the default value is used.`,
|
||||||
|
validationError.Option.Name,
|
||||||
|
validationError.Err.Error(),
|
||||||
|
),
|
||||||
|
Action{
|
||||||
|
Text: "Change",
|
||||||
|
Type: ActionTypeOpenSetting,
|
||||||
|
Payload: &ActionTypeOpenSettingPayload{
|
||||||
|
Key: validationError.Option.Key,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue