Refresh catalog on relevant errors

Most of a fix for #2846.  Fixes #2847. Fixes #2979.

Errors in the build process that could be fixed by refreshing the
catalog now cause the catalog to refresh, assuming we have not already
refreshed it recently and that we are not offline.

Other build commands will now not require refresh at startup, although
this has not been changed in this commit.