This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
commit 40ab38e7998b536eb47837e188ae08b8d510c4ba Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Fri Oct 19 11:43:57 2018 -0700 Ensure warnings only displayed once Some warnings were displayed repeatedly. Only display each warnings once. --- newt/downloader/downloader.go | 7 ++++--- newt/install/install.go | 18 +++++++++--------- newt/newtutil/newtutil.go | 14 ++++++++++++++ newt/project/project.go | 4 ++-- newt/repo/version.go | 13 ++++++------- newt/syscfg/restrict.go | 6 +++--- 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go index 58d8cda..ac0f113 100644 --- a/newt/downloader/downloader.go +++ b/newt/downloader/downloader.go @@ -30,6 +30,7 @@ import ( log "github.com/Sirupsen/logrus" + "mynewt.apache.org/newt/newt/newtutil" "mynewt.apache.org/newt/newt/settings" "mynewt.apache.org/newt/util" ) @@ -420,9 +421,9 @@ func setRemoteUrl(path string, remote string, url string, logCmd bool) error { } func warnWrongOriginUrl(path string, curUrl string, goodUrl string) { - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: Repo's \"origin\" remote points to unexpected URL: "+ - "%s; correcting it to %s. Repo contents may be incorrect.\n", + newtutil.OneTimeWarning( + "Repo's \"origin\" remote points to unexpected URL: "+ + "%s; correcting it to %s. Repo contents may be incorrect.", curUrl, goodUrl) } diff --git a/newt/install/install.go b/newt/install/install.go index ce32349..e97eb0f 100644 --- a/newt/install/install.go +++ b/newt/install/install.go @@ -121,11 +121,11 @@ import ( log "github.com/Sirupsen/logrus" + "mynewt.apache.org/newt/newt/compat" "mynewt.apache.org/newt/newt/deprepo" "mynewt.apache.org/newt/newt/newtutil" "mynewt.apache.org/newt/newt/repo" "mynewt.apache.org/newt/util" - "mynewt.apache.org/newt/newt/compat" ) type installOp int @@ -157,9 +157,9 @@ func detectVersion(r *repo.Repo) (newtutil.RepoVersion, error) { Commit: commit, } - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: Could not detect version of installed repo \"%s\"; "+ - "assuming %s\n", r.Name(), ver.String()) + newtutil.OneTimeWarning( + "Could not detect version of installed repo \"%s\"; assuming %s", + r.Name(), ver.String()) } log.Debugf("currently installed version of repo \"%s\": %s", @@ -292,9 +292,9 @@ func (inst *Installer) inferReqVers(repos []*repo.Repo) error { } if ver == nil { - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: Could not detect version of "+ - "requested repo %s:%s; assuming 0.0.0\n", + newtutil.OneTimeWarning( + "Could not detect version of requested repo "+ + "%s:%s; assuming 0.0.0", r.Name(), req.Ver.Commit) ver = &req.Ver @@ -732,7 +732,7 @@ func verifyRepoDirtyState(repos []*repo.Repo, force bool) error { s += "Specify the `-f` (force) switch to attempt anyway" return util.NewNewtError(s) } else { - util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", s) + newtutil.OneTimeWarning("%s", s) } } @@ -749,7 +749,7 @@ func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error { switch code { case compat.NEWT_COMPAT_WARN: - util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", msg) + newtutil.OneTimeWarning("%s", msg) case compat.NEWT_COMPAT_ERROR: errors = append(errors, msg) } diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go index 5b83bc8..258afab 100644 --- a/newt/newtutil/newtutil.go +++ b/newt/newtutil/newtutil.go @@ -201,3 +201,17 @@ func ReadConfig(dir string, filename string) (ycfg.YCfg, error) { func YCfgToYaml(yc ycfg.YCfg) string { return yaml.MapToYaml(yc.AllSettings()) } + +// Keeps track of warnings that have already been reported. +// [warning-text] => struct{} +var warnings = map[string]struct{}{} + +// Displays the specified warning if it has not been displayed yet. +func OneTimeWarning(text string, args ...interface{}) { + if _, ok := warnings[text]; !ok { + warnings[text] = struct{}{} + + body := fmt.Sprintf(text, args...) + util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", body) + } +} diff --git a/newt/project/project.go b/newt/project/project.go index e638d58..b7944e5 100644 --- a/newt/project/project.go +++ b/newt/project/project.go @@ -396,7 +396,7 @@ func (proj *Project) checkNewtVer() error { case compat.NEWT_COMPAT_GOOD: return nil case compat.NEWT_COMPAT_WARN: - util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg) + newtutil.OneTimeWarning("%s", msg) return nil case compat.NEWT_COMPAT_ERROR: return util.NewNewtError(msg) @@ -500,7 +500,7 @@ func (proj *Project) verifyNewtCompat() error { switch code { case compat.NEWT_COMPAT_GOOD: case compat.NEWT_COMPAT_WARN: - util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg) + newtutil.OneTimeWarning("%s", msg) case compat.NEWT_COMPAT_ERROR: errors = append(errors, msg) } diff --git a/newt/repo/version.go b/newt/repo/version.go index ae00f7c..d8dbfa2 100644 --- a/newt/repo/version.go +++ b/newt/repo/version.go @@ -392,9 +392,8 @@ func (r *Repo) inferVersion(commit string, vyVer *newtutil.RepoVersion) ( } } - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: Version mismatch in %s:%s; "+ - "repository.yml:%s, version.yml:%s\n", + newtutil.OneTimeWarning( + "Version mismatch in %s:%s; repository.yml:%s, version.yml:%s", r.Name(), commit, versString(ryVers), vyVer.String()) } else { // If the set of commits don't match a version from @@ -464,12 +463,12 @@ func (r *Repo) NonInstalledVersion( if ver == nil { if versionYmlErr == versionYmlMissing { - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: %s:%s does not contain a `version.yml` file.\n", + newtutil.OneTimeWarning( + "%s:%s does not contain a `version.yml` file.", r.Name(), commit) } else if versionYmlErr == versionYmlBad { - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: %s:%s contains a malformed `version.yml` file.\n", + newtutil.OneTimeWarning( + "%s:%s contains a malformed `version.yml` file.", r.Name(), commit) } } diff --git a/newt/syscfg/restrict.go b/newt/syscfg/restrict.go index c998fce..fe1ca83 100644 --- a/newt/syscfg/restrict.go +++ b/newt/syscfg/restrict.go @@ -59,8 +59,8 @@ import ( log "github.com/Sirupsen/logrus" + "mynewt.apache.org/newt/newt/newtutil" "mynewt.apache.org/newt/newt/parse" - "mynewt.apache.org/newt/util" ) type CfgRestrictionCode int @@ -201,8 +201,8 @@ func (cfg *Cfg) restrictionMet( val, err := parse.ParseAndEval(expr, settings) if err != nil { - util.StatusMessage(util.VERBOSITY_QUIET, - "WARNING: ignoring illegal expression for setting \"%s\": "+ + newtutil.OneTimeWarning( + "Ignoring illegal expression for setting \"%s\": "+ "`%s` %s\n", r.BaseSetting, r.Expr, err.Error()) return true }