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:
@@ -195,6 +195,9 @@ func TestBadPatterns(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Errorf("No error for pattern %q", pat)
|
||||
}
|
||||
if !IsParseError(err) {
|
||||
t.Error("Should have been a parse error:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1006,10 +1009,13 @@ func TestIssue4901(t *testing.T) {
|
||||
for i := 0; i < 2; i++ {
|
||||
err := pats.Load(".stignore")
|
||||
if err == nil {
|
||||
t.Fatalf("expected an error")
|
||||
t.Fatal("expected an error")
|
||||
}
|
||||
if fs.IsNotExist(err) {
|
||||
t.Fatalf("unexpected error type")
|
||||
t.Fatal("unexpected error type")
|
||||
}
|
||||
if !IsParseError(err) {
|
||||
t.Fatal("failure to load included file should be a parse error")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1094,9 +1100,13 @@ func TestPartialIncludeLine(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
if err := pats.Parse(bytes.NewBufferString(tc), ".stignore"); err == nil {
|
||||
err := pats.Parse(bytes.NewBufferString(tc), ".stignore")
|
||||
if err == nil {
|
||||
t.Fatal("should error out")
|
||||
}
|
||||
if !IsParseError(err) {
|
||||
t.Fatal("failure to load included file should be a parse error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,5 +1187,8 @@ func TestEmptyPatterns(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error("Should reject invalid pattern", tc)
|
||||
}
|
||||
if !IsParseError(err) {
|
||||
t.Fatal("bad pattern should be a parse error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user