You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/04/30 17:38:21 UTC

[mynewt-newt] branch master updated: Detect invalid repos in `project.yml`

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


The following commit(s) were added to refs/heads/master by this push:
     new eb8e5e9  Detect invalid repos in `project.yml`
eb8e5e9 is described below

commit eb8e5e99802ffe6b4a03a531a202a9b2bc00d374
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Apr 26 11:35:21 2019 -0700

    Detect invalid repos in `project.yml`
    
    This fixes #255.
    
    Newt was ignoring errors in repo definitions during `project.yml`
    parsing.  The reason these errors were being ignored was to allow newt
    to proceed in case of a specific error case: a missing `repository.yml`
    file.  If a `repository.yml` file is missing, newt recovers by
    cloning the corresponding repo and copying the file.  Ignoring the
    errors entirely is too coarse of a solution; legitimate errors are
    discarded, possibly causing a crash later.
    
    The solution is to distinguish missing `repository.yml` files from the
    other error cases.
---
 newt/project/project.go | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/newt/project/project.go b/newt/project/project.go
index 17515c7..4707934 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -417,7 +417,15 @@ func (proj *Project) loadRepoDeps(download bool) error {
 
 					depRepo := proj.repos[dep.Name]
 					if depRepo == nil {
-						depRepo, _ = proj.loadRepo(dep.Name, dep.Fields)
+						var err error
+						depRepo, err = proj.loadRepo(dep.Name, dep.Fields)
+						if err != nil {
+							// if `repository.yml` does not exist, it is not an
+							// error; we will just download a new copy.
+							if !util.IsNotExist(err) {
+								return nil, err
+							}
+						}
 						proj.repos[dep.Name] = depRepo
 					}
 					newRepos = append(newRepos, depRepo)
@@ -541,12 +549,19 @@ func (proj *Project) loadConfig() error {
 		repoName := strings.TrimPrefix(k, "repository.")
 		if repoName != k {
 			fields := yc.GetValStringMapString(k, nil)
-			r, _ := proj.loadRepo(repoName, fields)
-
+			r, err := proj.loadRepo(repoName, fields)
+			if err != nil {
+				// if `repository.yml` does not exist, it is not an error; we
+				// will just download a new copy.
+				if !util.IsNotExist(err) {
+					return err
+				}
+			}
 			verReqs, err := newtutil.ParseRepoVersionReqs(fields["vers"])
 			if err != nil {
 				return util.FmtNewtError(
-					"Repo \"%s\" contains invalid version requirement: %s (%s)",
+					"Repo \"%s\" contains invalid version requirement: "+
+						"%s (%s)",
 					repoName, fields["vers"], err.Error())
 			}