mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Handle transient errors in config loading etc.
As in: Get the Kubernetes site to build with the new Hugo version. Updates #10947
This commit is contained in:
@@ -182,6 +182,7 @@ func (c Config) cloneForLang() *Config {
|
||||
}
|
||||
|
||||
func (c *Config) CompileConfig() error {
|
||||
var transientErr error
|
||||
s := c.Timeout
|
||||
if _, err := strconv.Atoi(s); err == nil {
|
||||
// A number, assume seconds.
|
||||
@@ -209,7 +210,8 @@ func (c *Config) CompileConfig() error {
|
||||
}
|
||||
f, found := outputFormats.GetByName(format)
|
||||
if !found {
|
||||
return fmt.Errorf("unknown output format %q for kind %q", format, kind)
|
||||
transientErr = fmt.Errorf("unknown output format %q for kind %q", format, kind)
|
||||
continue
|
||||
}
|
||||
kindOutputFormats[kind] = append(kindOutputFormats[kind], f)
|
||||
}
|
||||
@@ -288,6 +290,7 @@ func (c *Config) CompileConfig() error {
|
||||
IgnoreFile: ignoreFile,
|
||||
MainSections: c.MainSections,
|
||||
Clock: clock,
|
||||
transientErr: transientErr,
|
||||
}
|
||||
|
||||
for _, s := range allDecoderSetups {
|
||||
@@ -323,6 +326,11 @@ type ConfigCompiled struct {
|
||||
IgnoreFile func(filename string) bool
|
||||
MainSections []string
|
||||
Clock time.Time
|
||||
|
||||
// This is set to the last transient error found during config compilation.
|
||||
// With themes/modules we compule the configuration in multiple passes, and
|
||||
// errors with missing output format definitions may resolve itself.
|
||||
transientErr error
|
||||
}
|
||||
|
||||
// This may be set after the config is compiled.
|
||||
@@ -565,6 +573,16 @@ type Configs struct {
|
||||
configLangs []config.AllProvider
|
||||
}
|
||||
|
||||
// transientErr returns the last transient error found during config compilation.
|
||||
func (c *Configs) transientErr() error {
|
||||
for _, l := range c.LanguageConfigSlice {
|
||||
if l.C.transientErr != nil {
|
||||
return l.C.transientErr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Configs) IsZero() bool {
|
||||
// A config always has at least one language.
|
||||
return c == nil || len(c.Languages) == 0
|
||||
|
@@ -63,13 +63,19 @@ func LoadConfig(d ConfigSourceDescriptor) (*Configs, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load modules: %w", err)
|
||||
}
|
||||
|
||||
if len(l.ModulesConfigFiles) > 0 {
|
||||
// Config merged in from modules.
|
||||
// Re-read the config.
|
||||
configs, err = FromLoadConfigResult(d.Fs, res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create config: %w", err)
|
||||
return nil, fmt.Errorf("failed to create config from modules config: %w", err)
|
||||
}
|
||||
if err := configs.transientErr(); err != nil {
|
||||
return nil, fmt.Errorf("failed to create config from modules config: %w", err)
|
||||
}
|
||||
} else if err := configs.transientErr(); err != nil {
|
||||
return nil, fmt.Errorf("failed to create config: %w", err)
|
||||
}
|
||||
|
||||
configs.Modules = moduleConfig.ActiveModules
|
||||
|
Reference in New Issue
Block a user