summaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-17 13:12:49 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-05-17 22:13:29 +0200
commit05542130ba0205d3d8d14575b7e49ed42a855b9a (patch)
treebb94df8ba48b349bdcb18d254af51a38722bef13 /config
parent5251f015bfff40b49f92f8855834d5682f925860 (diff)
Handle transient errors in config loading etc.
As in: Get the Kubernetes site to build with the new Hugo version. Updates #10947
Diffstat (limited to 'config')
-rw-r--r--config/allconfig/allconfig.go20
-rw-r--r--config/allconfig/load.go8
2 files changed, 26 insertions, 2 deletions
diff --git a/config/allconfig/allconfig.go b/config/allconfig/allconfig.go
index 4daae3ccb..6731b9003 100644
--- a/config/allconfig/allconfig.go
+++ b/config/allconfig/allconfig.go
@@ -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
diff --git a/config/allconfig/load.go b/config/allconfig/load.go
index 9f27e867e..2d1a84423 100644
--- a/config/allconfig/load.go
+++ b/config/allconfig/load.go
@@ -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