Quellcode durchsuchen

repo/editor: hide internal error detail

Prevent exposure of server path
Unknwon vor 6 Jahren
Ursprung
Commit
512a900202
4 geänderte Dateien mit 12 neuen und 5 gelöschten Zeilen
  1. 1 0
      conf/locale/locale_en-US.ini
  2. 2 0
      models/errors/errors.go
  3. 2 2
      pkg/bindata/bindata.go
  4. 7 3
      routes/repo/editor.go

+ 1 - 0
conf/locale/locale_en-US.ini

@@ -520,6 +520,7 @@ editor.file_changed_while_editing = File content has been changed since you star
 editor.file_already_exists = A file with name '%s' already exists in this repository.
 editor.no_changes_to_show = There are no changes to show.
 editor.fail_to_update_file = Failed to update/create file '%s' with error: %v
+editor.fail_to_delete_file = Failed to delete file '%s' with error: %v
 editor.add_subdir = Add subdirectory...
 editor.unable_to_upload_files = Failed to upload files to '%s' with error: %v
 editor.upload_files_to_dir = Upload files to '%s'

+ 2 - 0
models/errors/errors.go

@@ -6,6 +6,8 @@ package errors
 
 import "errors"
 
+var InternalServerError = errors.New("internal server error")
+
 // New is a wrapper of real errors.New function.
 func New(text string) error {
 	return errors.New(text)

Datei-Diff unterdrückt, da er zu groß ist
+ 2 - 2
pkg/bindata/bindata.go


+ 7 - 3
routes/repo/editor.go

@@ -15,6 +15,7 @@ import (
 
 	"github.com/gogs/git-module"
 	"github.com/gogs/gogs/models"
+	"github.com/gogs/gogs/models/errors"
 	"github.com/gogs/gogs/pkg/context"
 	"github.com/gogs/gogs/pkg/form"
 	"github.com/gogs/gogs/pkg/setting"
@@ -276,8 +277,9 @@ func editFilePost(c *context.Context, f form.EditRepoFile, isNewFile bool) {
 		Content:      strings.Replace(f.Content, "\r", "", -1),
 		IsNewFile:    isNewFile,
 	}); err != nil {
+		log.Error(2, "Failed to update repo file: %v", err)
 		c.FormErr("TreePath")
-		c.RenderWithErr(c.Tr("repo.editor.fail_to_update_file", f.TreePath, err), EDIT_FILE, &f)
+		c.RenderWithErr(c.Tr("repo.editor.fail_to_update_file", f.TreePath, errors.InternalServerError), EDIT_FILE, &f)
 		return
 	}
 
@@ -380,7 +382,8 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
 		TreePath:     c.Repo.TreePath,
 		Message:      message,
 	}); err != nil {
-		c.ServerError("DeleteRepoFile", err)
+		log.Error(2, "Failed to delete repo file: %v", err)
+		c.RenderWithErr(c.Tr("repo.editor.fail_to_delete_file", c.Repo.TreePath, errors.InternalServerError), DELETE_FILE, &f)
 		return
 	}
 
@@ -499,8 +502,9 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
 		Message:      message,
 		Files:        f.Files,
 	}); err != nil {
+		log.Error(2, "Failed to upload files: %v", err)
 		c.FormErr("TreePath")
-		c.RenderWithErr(c.Tr("repo.editor.unable_to_upload_files", f.TreePath, err), UPLOAD_FILE, &f)
+		c.RenderWithErr(c.Tr("repo.editor.unable_to_upload_files", f.TreePath, errors.InternalServerError), UPLOAD_FILE, &f)
 		return
 	}
 

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.