Keep certificate-directory problems on the station window and leave a hand-edit untouched until Save.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-11 19:29:32 +02:00
co-authored by Cursor
parent 775d1b5c82
commit d21e7051d7
8 changed files with 165 additions and 40 deletions
+11 -16
View File
@@ -73,7 +73,7 @@ func loadConfig(path string) (configLoad, error) {
}
return configLoad{form: form, detail: fmt.Errorf("the file could not be read: %w", err).Error()}, nil
}
return parseConfig(path, body)
return parseConfig(path, body, true)
}
// ConfigForm is the eight fields the Config window edits.
@@ -104,7 +104,7 @@ func templateForm() (ConfigForm, error) {
return ConfigForm{CertificateDir: "./funknetz", LogFile: logFile}, nil
}
func parseConfig(path string, body []byte) (configLoad, error) {
func parseConfig(path string, body []byte, rewrite bool) (configLoad, error) {
var shape fileShape
if err := jsonv2.Unmarshal(body, &shape); err != nil {
form, ferr := templateForm()
@@ -137,8 +137,10 @@ func parseConfig(path string, body []byte) (configLoad, error) {
if err != nil {
return configLoad{}, err
}
if err := rewriteConfig(path, shape); err != nil {
return configLoad{}, fmt.Errorf("the file could not be read: %w", err)
if rewrite {
if err := rewriteConfig(path, shape); err != nil {
return configLoad{}, fmt.Errorf("the file could not be read: %w", err)
}
}
}
cfg, err := parseOperational(shape)
@@ -149,30 +151,23 @@ func parseConfig(path string, body []byte) (configLoad, error) {
}
func finish(shape fileShape, cfg loaded) (configLoad, error) {
form, err := formFromShape(shape)
if err != nil {
return configLoad{}, err
}
form := formFromShape(shape)
if cfg.certFatal != "" {
return configLoad{cfg: cfg, form: form, detail: cfg.certFatal}, nil
return configLoad{cfg: cfg, form: form, loaded: true, detail: cfg.certFatal}, nil
}
return configLoad{cfg: cfg, form: form, loaded: true, detail: cfg.logNotice}, nil
}
func refused(shape fileShape, cause error) (configLoad, error) {
form, err := formFromShape(shape)
if err != nil {
return configLoad{}, err
}
return configLoad{form: form, detail: cause.Error()}, nil
return configLoad{form: formFromShape(shape), detail: cause.Error()}, nil
}
func formFromShape(shape fileShape) (ConfigForm, error) {
func formFromShape(shape fileShape) ConfigForm {
fallback, err := templateForm()
if err != nil {
fallback = ConfigForm{CertificateDir: "./funknetz"}
}
return mergeSalvage(shape, fallback), nil
return mergeSalvage(shape, fallback)
}
func mergeSalvage(shape fileShape, fallback ConfigForm) ConfigForm {