Skip to content

Commit

Permalink
commands: Make the error handling for the mod commands more lenient
Browse files Browse the repository at this point in the history
So it at least is possible to do a `hugo mod clean --all` if the cache is in a funky state.
  • Loading branch information
bep committed Sep 17, 2021
1 parent 1cabf61 commit 13ad840
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion commands/commandeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions commands/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 13ad840

Please sign in to comment.