Browse Source

repo/editor: hide internal error detail

Prevent exposure of server path
pull/4799/merge
Unknwon 6 years ago
parent
commit
512a900202
No known key found for this signature in database
GPG Key ID: 7A02C406FAC875A2
  1. 1
      conf/locale/locale_en-US.ini
  2. 2
      models/errors/errors.go
  3. 12
      pkg/bindata/bindata.go
  4. 10
      routes/repo/editor.go

1
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.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.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_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.add_subdir = Add subdirectory...
editor.unable_to_upload_files = Failed to upload files to '%s' with error: %v editor.unable_to_upload_files = Failed to upload files to '%s' with error: %v
editor.upload_files_to_dir = Upload files to '%s' editor.upload_files_to_dir = Upload files to '%s'

2
models/errors/errors.go

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

12
pkg/bindata/bindata.go

File diff suppressed because one or more lines are too long

10
routes/repo/editor.go

@ -15,6 +15,7 @@ import (
"github.com/gogs/git-module" "github.com/gogs/git-module"
"github.com/gogs/gogs/models" "github.com/gogs/gogs/models"
"github.com/gogs/gogs/models/errors"
"github.com/gogs/gogs/pkg/context" "github.com/gogs/gogs/pkg/context"
"github.com/gogs/gogs/pkg/form" "github.com/gogs/gogs/pkg/form"
"github.com/gogs/gogs/pkg/setting" "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), Content: strings.Replace(f.Content, "\r", "", -1),
IsNewFile: isNewFile, IsNewFile: isNewFile,
}); err != nil { }); err != nil {
log.Error(2, "Failed to update repo file: %v", err)
c.FormErr("TreePath") 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 return
} }
@ -380,7 +382,8 @@ func DeleteFilePost(c *context.Context, f form.DeleteRepoFile) {
TreePath: c.Repo.TreePath, TreePath: c.Repo.TreePath,
Message: message, Message: message,
}); err != nil { }); 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 return
} }
@ -499,8 +502,9 @@ func UploadFilePost(c *context.Context, f form.UploadRepoFile) {
Message: message, Message: message,
Files: f.Files, Files: f.Files,
}); err != nil { }); err != nil {
log.Error(2, "Failed to upload files: %v", err)
c.FormErr("TreePath") 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 return
} }

Loading…
Cancel
Save