commands: Make the error handling for the mod commands more lenient - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 13ad8408fc6b645b12898fb8053388fc4848dfbd
 (DIR) parent 1cabf61ddf96b89c95c3ba77a985168184920feb
 (HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Fri, 17 Sep 2021 17:16:34 +0200
       
       commands: Make the error handling for the mod commands more lenient
       
       So it at least is possible to do a `hugo mod clean --all` if the cache is in a funky state.
       
       Diffstat:
         M commands/commandeer.go              |       5 ++++-
         M commands/mod.go                     |       5 +++--
       
       2 files changed, 7 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/commands/commandeer.go b/commands/commandeer.go
       @@ -323,8 +323,11 @@ func (c *commandeer) loadConfig() error {
                        // 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 c.mustHaveConfigFile || !moduleNotFoundRe.MatchString(err.Error()) {
       +                if c.mustHaveConfigFile || (c.failOnInitErr && !moduleNotFoundRe.MatchString(err.Error())) {
                                return err
       +                } else {
       +                        // Just make it a warning.
       +                        c.logger.Warnln(err)
                        }
                } else if c.mustHaveConfigFile && len(configFiles) == 0 {
                        return hugolib.ErrNoConfigFile
 (DIR) diff --git a/commands/mod.go b/commands/mod.go
       @@ -71,11 +71,12 @@ Also note that if you configure a positive maxAge for the "modules" file cache, 
                                if all {
                                        com, err := c.initConfig(false)
        
       -                                if err != nil && !moduleNotFoundRe.MatchString(err.Error()) {
       +                                if err != nil && com == nil {
                                                return err
                                        }
        
       -                                _, err = com.hugo().FileCaches.ModulesCache().Prune(true)
       +                                count, err := com.hugo().FileCaches.ModulesCache().Prune(true)
       +                                com.logger.Printf("Deleted %d files from module cache.", count)
                                        return err
                                }
                                return c.withModsClient(true, func(c *modules.Client) error {