mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portbase/config"
|
||||
"github.com/safing/portbase/modules"
|
||||
)
|
||||
|
||||
var module *modules.Module
|
||||
|
||||
func init() {
|
||||
module = modules.Register("notifications", prep, start, nil, "database", "base")
|
||||
module = modules.Register("notifications", prep, start, nil, "database", "config", "base")
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
|
@ -22,6 +24,43 @@ func start() error {
|
|||
return err
|
||||
}
|
||||
|
||||
showConfigLoadingErrors()
|
||||
|
||||
go module.StartServiceWorker("cleaner", 1*time.Second, cleaner)
|
||||
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