mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	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>
This commit is contained in:
		@@ -165,7 +165,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
 | 
			
		||||
 | 
			
		||||
// GetEditorConfig returns a editorconfig JSON string for given treePath or "null"
 | 
			
		||||
func GetEditorConfig(ctx *context.Context, treePath string) string {
 | 
			
		||||
	ec, err := ctx.Repo.GetEditorconfig()
 | 
			
		||||
	ec, _, err := ctx.Repo.GetEditorconfig()
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		def, err := ec.GetDefinitionForFilename(treePath)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ func SetEditorconfigIfExists(ctx *context.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ec, err := ctx.Repo.GetEditorconfig()
 | 
			
		||||
	ec, _, err := ctx.Repo.GetEditorconfig()
 | 
			
		||||
 | 
			
		||||
	if err != nil && !git.IsErrNotExist(err) {
 | 
			
		||||
		description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
 | 
			
		||||
 
 | 
			
		||||
@@ -346,11 +346,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
			
		||||
	ctx.Data["RawFileLink"] = rawLink + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
 | 
			
		||||
 | 
			
		||||
	if ctx.Repo.TreePath == ".editorconfig" {
 | 
			
		||||
		_, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
 | 
			
		||||
		ctx.Data["FileError"] = editorconfigErr
 | 
			
		||||
		_, editorconfigWarning, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
 | 
			
		||||
		if editorconfigWarning != nil {
 | 
			
		||||
			ctx.Data["FileWarning"] = strings.TrimSpace(editorconfigWarning.Error())
 | 
			
		||||
		}
 | 
			
		||||
		if editorconfigErr != nil {
 | 
			
		||||
			ctx.Data["FileError"] = strings.TrimSpace(editorconfigErr.Error())
 | 
			
		||||
		}
 | 
			
		||||
	} else if ctx.Repo.IsIssueConfig(ctx.Repo.TreePath) {
 | 
			
		||||
		_, issueConfigErr := ctx.Repo.GetIssueConfig(ctx.Repo.TreePath, ctx.Repo.Commit)
 | 
			
		||||
		ctx.Data["FileError"] = issueConfigErr
 | 
			
		||||
		if issueConfigErr != nil {
 | 
			
		||||
			ctx.Data["FileError"] = strings.TrimSpace(issueConfigErr.Error())
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	isDisplayingSource := ctx.FormString("display") == "source"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user