From a0489c2dfd3ceb4d0702de0da7a4af3eabce05e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 31 Aug 2021 12:08:11 +0200 Subject: [PATCH] Avoid failing with "module not found" for hugo mod init and similar Fixes #8940 --- commands/commandeer.go | 7 ++++++- hugolib/config.go | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/commands/commandeer.go b/commands/commandeer.go index bac96fa7a..b2a995ae6 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -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 } diff --git a/hugolib/config.go b/hugolib/config.go index aa9c81104..cdce19d6e 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -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 }