]> source.dussan.org Git - gitea.git/commitdiff
Fix 500 when repo has invalid .editorconfig 59/head
authorAndrey Nering <andrey.nering@gmail.com>
Thu, 3 Nov 2016 22:45:16 +0000 (20:45 -0200)
committerAndrey Nering <andrey.nering@gmail.com>
Sat, 5 Nov 2016 15:33:41 +0000 (13:33 -0200)
Creating a notice instead

routers/repo/commit.go
routers/repo/middlewares.go [new file with mode: 0644]
routers/repo/pull.go
routers/repo/view.go

index a8e96f0e5edd7dfad82a947aa561ac1118261afc..4a4d4b12319dfdb795f8b51ca90812254315acf1 100644 (file)
@@ -179,12 +179,10 @@ func Diff(ctx *context.Context) {
                }
        }
 
-       ec, err := ctx.Repo.GetEditorconfig()
-       if err != nil && !git.IsErrNotExist(err) {
-               ctx.Handle(500, "ErrGettingEditorconfig", err)
+       setEditorconfigIfExists(ctx)
+       if ctx.Written() {
                return
        }
-       ctx.Data["Editorconfig"] = ec
 
        ctx.Data["CommitID"] = commitID
        ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
diff --git a/routers/repo/middlewares.go b/routers/repo/middlewares.go
new file mode 100644 (file)
index 0000000..f025765
--- /dev/null
@@ -0,0 +1,23 @@
+package repo
+
+import (
+       "fmt"
+
+       "github.com/go-gitea/gitea/models"
+       "github.com/go-gitea/gitea/modules/context"
+       "github.com/gogits/git-module"
+)
+
+func setEditorconfigIfExists(ctx *context.Context) {
+       ec, err := ctx.Repo.GetEditorconfig()
+
+       if err != nil && !git.IsErrNotExist(err) {
+               description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
+               if err := models.CreateRepositoryNotice(description); err != nil {
+                       ctx.Handle(500, "ErrCreatingReporitoryNotice", err)
+               }
+               return
+       }
+
+       ctx.Data["Editorconfig"] = ec
+}
index baa8c1d0b5d6443866b91848452f377ac06d770a..6dbb2b6025c9d2d16ad363fdfa6d65afdc172470 100644 (file)
@@ -368,12 +368,10 @@ func ViewPullFiles(ctx *context.Context) {
                return
        }
 
-       ec, err := ctx.Repo.GetEditorconfig()
-       if err != nil && !git.IsErrNotExist(err) {
-               ctx.Handle(500, "ErrGettingEditorconfig", err)
+       setEditorconfigIfExists(ctx)
+       if ctx.Written() {
                return
        }
-       ctx.Data["Editorconfig"] = ec
 
        headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
        ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
@@ -627,12 +625,10 @@ func CompareAndPullRequest(ctx *context.Context) {
                }
        }
 
-       ec, err := ctx.Repo.GetEditorconfig()
-       if err != nil && !git.IsErrNotExist(err) {
-               ctx.Handle(500, "ErrGettingEditorconfig", err)
+       setEditorconfigIfExists(ctx)
+       if ctx.Written() {
                return
        }
-       ctx.Data["Editorconfig"] = ec
 
        ctx.HTML(200, COMPARE_PULL)
 }
index 3bb551f2e0749e80b3cfe94a9a35f6e1bbfc0a0d..ee49d4da15ab75a7df9ebdfd8558fc3fc0419200 100644 (file)
@@ -245,12 +245,10 @@ func Home(ctx *context.Context) {
                return
        }
 
-       ec, err := ctx.Repo.GetEditorconfig()
-       if err != nil && !git.IsErrNotExist(err) {
-               ctx.Handle(500, "Repo.GetEditorconfig", err)
+       setEditorconfigIfExists(ctx)
+       if ctx.Written() {
                return
        }
-       ctx.Data["Editorconfig"] = ec
 
        var treeNames []string
        paths := make([]string, 0, 5)