mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Avoid failing with "module not found" for hugo mod init and similar
Fixes #8940
This commit is contained in:
parent
0fc2ce9e4b
commit
a0489c2dfd
2 changed files with 11 additions and 2 deletions
|
@ -309,7 +309,12 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
|
|||
doWithConfig)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
// We should improve the error handling here,
|
||||
// but with hugo mod init and similar there is a chicken and egg situation
|
||||
// with modules already configured in config.toml, so ignore those errors.
|
||||
if mustHaveConfigFile || !moduleNotFoundRe.MatchString(err.Error()) {
|
||||
return err
|
||||
}
|
||||
} else if mustHaveConfigFile && len(configFiles) == 0 {
|
||||
return hugolib.ErrNoConfigFile
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
|
|||
return nil
|
||||
}
|
||||
|
||||
_, modulesConfigFiles, err := l.collectModules(modulesConfig, l.cfg, collectHook)
|
||||
_, modulesConfigFiles, modulesCollectErr := l.collectModules(modulesConfig, l.cfg, collectHook)
|
||||
if err != nil {
|
||||
return l.cfg, configFiles, err
|
||||
}
|
||||
|
@ -166,6 +166,10 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
|
|||
return l.cfg, configFiles, err
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
err = modulesCollectErr
|
||||
}
|
||||
|
||||
return l.cfg, configFiles, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue