gui, lib/ignore: Handle editing ignores with error (fixes #5425) (#6757)

This changes the error handling in loading ignores slightly:

- There is a new ParseError type that is returned as the error
  (somewhere in the chain) when the problem was not an I/O error loading
  the file, but some issue with the contents.

- If the file was read successfully but not parsed successfully we still
  return the lines read (in addition to nil patterns and a ParseError).

- In the API, if the error IsParseError then we return a successful
  HTTP response with the lines and the actual error included in the JSON
  object.

- In the GUI, as long as the HTTP call to load the ignores was
  successful we can edit the ignores. If there was an error we show this
  as a validation error on the dialog.

Also some cleanup on the Javascript side as it for some reason used
jQuery instead of Angular for this editor...
This commit is contained in:
Jakob Borg
2020-06-18 11:04:00 +02:00
committed by GitHub
parent 8cf9d91ed4
commit 946170f3fc
6 changed files with 123 additions and 39 deletions
+14 -4
View File
@@ -43,6 +43,7 @@ import (
"github.com/syncthing/syncthing/lib/discover"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/ignore"
"github.com/syncthing/syncthing/lib/locations"
"github.com/syncthing/syncthing/lib/logger"
"github.com/syncthing/syncthing/lib/model"
@@ -1161,15 +1162,16 @@ func (s *service) getDBIgnores(w http.ResponseWriter, r *http.Request) {
folder := qs.Get("folder")
ignores, patterns, err := s.model.GetIgnores(folder)
if err != nil {
lines, patterns, err := s.model.GetIgnores(folder)
if err != nil && !ignore.IsParseError(err) {
http.Error(w, err.Error(), 500)
return
}
sendJSON(w, map[string][]string{
"ignore": ignores,
sendJSON(w, map[string]interface{}{
"ignore": lines,
"expanded": patterns,
"error": errorString(err),
})
}
@@ -1750,3 +1752,11 @@ func checkExpiry(cert tls.Certificate) error {
return nil
}
func errorString(err error) *string {
if err != nil {
msg := err.Error()
return &msg
}
return nil
}