diff options
author | Yoan Blanc <yoan@dosimple.ch> | 2023-04-06 22:01:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-06 16:01:20 -0400 |
commit | 9b416b2e36a035672226d4b83c6b7e87578b17fe (patch) | |
tree | ede783a30f3de218f5db6a49d82a786b1c7c57d2 /modules/context/repo.go | |
parent | 797babbfcbcf845fe12c8659fffa1693ec4708bb (diff) | |
download | gitea-9b416b2e36a035672226d4b83c6b7e87578b17fe.tar.gz gitea-9b416b2e36a035672226d4b83c6b7e87578b17fe.zip |
Use graceful editorconfig loader to reduce errors when loading malformed editorconfigs (#21257)
The _graceful_ should fail less when the `.editorconfig` file isn't
properly written, e.g. boolean values from YAML or unparseable numbers
(when a number is expected). As is... information is lost as the
_warning_ (a go-multierror.Error) is ignored. If anybody knows how to
send them to the UI as warning; any help is appreciated.
Closes #20694
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r-- | modules/context/repo.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index 820e756fbd..9d45a6019a 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -240,35 +240,34 @@ func (r *Repository) FileExists(path, branch string) (bool, error) { // GetEditorconfig returns the .editorconfig definition if found in the // HEAD of the default repo branch. -func (r *Repository) GetEditorconfig(optCommit ...*git.Commit) (*editorconfig.Editorconfig, error) { +func (r *Repository) GetEditorconfig(optCommit ...*git.Commit) (cfg *editorconfig.Editorconfig, warning, err error) { if r.GitRepo == nil { - return nil, nil + return nil, nil, nil } - var ( - err error - commit *git.Commit - ) + + var commit *git.Commit + if len(optCommit) != 0 { commit = optCommit[0] } else { commit, err = r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch) if err != nil { - return nil, err + return nil, nil, err } } treeEntry, err := commit.GetTreeEntryByPath(".editorconfig") if err != nil { - return nil, err + return nil, nil, err } if treeEntry.Blob().Size() >= setting.UI.MaxDisplayFileSize { - return nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"} + return nil, nil, git.ErrNotExist{ID: "", RelPath: ".editorconfig"} } reader, err := treeEntry.Blob().DataAsync() if err != nil { - return nil, err + return nil, nil, err } defer reader.Close() - return editorconfig.Parse(reader) + return editorconfig.ParseGraceful(reader) } // RetrieveBaseRepo retrieves base repository |