mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
commands, hugolib: Get file context in "config parse failed" errors
Fixes #5325
This commit is contained in:
@@ -16,10 +16,11 @@ package hugolib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
|
||||
"github.com/gohugoio/hugo/hugolib/paths"
|
||||
_errors "github.com/pkg/errors"
|
||||
|
||||
@@ -106,12 +107,23 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
|
||||
v.SetConfigFile(configFilenames[0])
|
||||
v.AddConfigPath(d.Path)
|
||||
|
||||
applyFileContext := func(filename string, err error) error {
|
||||
err, _ = herrors.WithFileContextForFile(
|
||||
err,
|
||||
filename,
|
||||
filename,
|
||||
fs,
|
||||
herrors.SimpleLineMatcher)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var configFileErr error
|
||||
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
if _, ok := err.(viper.ConfigParseError); ok {
|
||||
return nil, configFiles, err
|
||||
return nil, configFiles, applyFileContext(v.ConfigFileUsed(), err)
|
||||
}
|
||||
configFileErr = ErrNoConfigFile
|
||||
}
|
||||
@@ -129,7 +141,7 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
|
||||
return nil, configFiles, fmt.Errorf("Unable to open Config file.\n (%s)\n", err)
|
||||
}
|
||||
if err = v.MergeConfig(r); err != nil {
|
||||
return nil, configFiles, fmt.Errorf("Unable to parse/merge Config file (%s).\n (%s)\n", configFile, err)
|
||||
return nil, configFiles, applyFileContext(configFile, err)
|
||||
}
|
||||
configFiles = append(configFiles, configFile)
|
||||
}
|
||||
|
Reference in New Issue
Block a user