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:
+14
-4
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user