This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git

commit e6d8b5e429e3b2787fd835d9b9fccfb85ae1098d
Author: Szymon Janc <[email protected]>
AuthorDate: Mon Oct 19 17:46:37 2026 +0200

    newt/cli: Report errors from loading package repos on upgrade
    
    Error from GetPkgRepos() was ignored, so invalid "repository.*"
    definitions in pkg.yml (bad version, missing type or url, unreadable
    patches directory) made "newt upgrade" silently do nothing and exit
    with status 0. Report the error.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/cli/project_cmds.go     |  4 ++-
 newt/error_reporting_test.go | 58 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go
index eb10191e..4caa9f21 100644
--- a/newt/cli/project_cmds.go
+++ b/newt/cli/project_cmds.go
@@ -130,7 +130,9 @@ func upgradeRunCmd(cmd *cobra.Command, args []string) {
        proj := TryGetOrDownloadProject()
        interfaces.SetProject(proj)
 
-       proj.GetPkgRepos()
+       if err := proj.GetPkgRepos(); err != nil {
+               NewtUsage(nil, err)
+       }
        proj.SetGitEnvVariables()
 
        pred := makeRepoPredicate(args)
diff --git a/newt/error_reporting_test.go b/newt/error_reporting_test.go
index bed2f4d2..ea83b336 100644
--- a/newt/error_reporting_test.go
+++ b/newt/error_reporting_test.go
@@ -17,10 +17,11 @@
  * under the License.
  */
 
-
 package main
 
 import (
+       "os"
+       "path/filepath"
        "strings"
        "testing"
 )
@@ -48,6 +49,24 @@ func errorReportingExpectFail(t *testing.T, dir string,
        return out
 }
 
+// errorReportingWriteFiles creates files in dir. files maps paths relative
+// to dir to contents.
+func errorReportingWriteFiles(t *testing.T, dir string,
+       files map[string]string) {
+
+       t.Helper()
+
+       for name, content := range files {
+               path := filepath.Join(dir, filepath.FromSlash(name))
+               if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+                       t.Fatal(err)
+               }
+               if err := os.WriteFile(path, []byte(content), 0644); err != nil 
{
+                       t.Fatal(err)
+               }
+       }
+}
+
 // Unknown commands and flags must make newt exit with an error.
 func TestErrorReportingUnknownCommand(t *testing.T) {
        dir := t.TempDir()
@@ -63,3 +82,40 @@ func TestErrorReportingUnknownCommand(t *testing.T) {
                        "target", "show", "--nosuchflag")
        })
 }
+
+// Invalid external repository definitions in pkg.yml must make newt upgrade
+// fail instead of being silently ignored.
+func TestErrorReportingUpgradePkgRepos(t *testing.T) {
+       tests := []struct {
+               name string
+               repo string
+               msg  string
+       }{
+               {
+                       name: "bad-version",
+                       repo: "    type: git\n    vers: notaversion\n" +
+                               "    url: https://dummy.invalid/ext.git\n";,
+                       msg: `Repo "ext" contains invalid version requirement`,
+               },
+               {
+                       name: "missing-type",
+                       repo: "    vers: 0.0.0\n" +
+                               "    url: https://dummy.invalid/ext.git\n";,
+                       msg: "Missing type for repository ext",
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       dir := t.TempDir()
+                       errorReportingWriteFiles(t, dir, map[string]string{
+                               "project.yml": "project.name: test\n",
+                               "apps/ext/pkg.yml": "pkg.name: apps/ext\n" +
+                                       "pkg.type: lib\n" +
+                                       "repository.ext:\n" + tt.repo,
+                       })
+
+                       errorReportingExpectFail(t, dir, []string{tt.msg}, 
"upgrade")
+               })
+       }
+}

Reply via email to