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 51a68da160eb618e68de5572c8fc462e4b912469
Author: Szymon Janc <[email protected]>
AuthorDate: Mon Oct 19 17:49:56 2026 +0200

    newt/builder: Fail load and debug if BSP has no script
    
    "newt load" with a BSP that does not set bsp.downloadscript printed
    "Loading app image into slot 1" and exited with status 0 without
    loading anything. "newt debug" without bsp.debugscript failed with
    "fork/exec : no such file or directory". Report an error naming the
    missing BSP setting in both cases.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/builder/load.go         | 21 ++++++++++++++++++++-
 newt/error_reporting_test.go | 19 +++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/newt/builder/load.go b/newt/builder/load.go
index 106d5992..2db5e513 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -137,11 +137,21 @@ func RunOptionalCheck(checkScript string, env 
map[string]string) error {
        return nil
 }
 
+// missingBspScriptError returns an error indicating that the BSP does not
+// specify a script required by an operation.
+func missingBspScriptError(bspPkg *pkg.BspPackage, op string,
+       key string) error {
+
+       return util.FmtNewtError("cannot %s: BSP \"%s\" does not specify %s",
+               op, bspPkg.FullName(), key)
+}
+
 func Load(binBasePath string, bspPkg *pkg.BspPackage,
        extraEnvSettings map[string]string) error {
 
        if bspPkg.DownloadScript == "" {
-               return nil
+               return missingBspScriptError(bspPkg, "load image",
+                       "bsp.downloadscript")
        }
 
        env := BasicEnvVars(binBasePath, bspPkg)
@@ -194,6 +204,11 @@ func (b *Builder) Load(imageSlot int, extraJtagCmd string, 
imgFilename string) e
                env["EXTRA_JTAG_CMD"] = extraJtagCmd
        }
 
+       if b.targetBuilder.bspPkg.DownloadScript == "" {
+               return missingBspScriptError(b.targetBuilder.bspPkg, "load 
image",
+                       "bsp.downloadscript")
+       }
+
        if _, ok := env["BOOT_LOADER"]; ok {
                util.StatusMessage(util.VERBOSITY_DEFAULT,
                        "Loading bootloader (%s)\n", imgFilename)
@@ -266,6 +281,10 @@ func (b *Builder) debugBin(binPath string, extraJtagCmd 
string, reset bool,
        binBasePath := binPath
        bspPkg := b.targetBuilder.bspPkg
 
+       if bspPkg.DebugScript == "" {
+               return missingBspScriptError(bspPkg, "debug", "bsp.debugscript")
+       }
+
        env, err := b.EnvVars(0)
        if err != nil {
                return err
diff --git a/newt/error_reporting_test.go b/newt/error_reporting_test.go
index b95321e3..4762ea7a 100644
--- a/newt/error_reporting_test.go
+++ b/newt/error_reporting_test.go
@@ -137,3 +137,22 @@ func TestErrorReportingEmptyToolPath(t *testing.T) {
        errorReportingExpectFail(t, dir,
                []string{"compiler.path.cc is not set in"}, "build", "app")
 }
+
+// Loading or debugging with a BSP that does not specify the required script
+// must fail with an explanation.
+func TestErrorReportingMissingBspScript(t *testing.T) {
+       t.Run("load", func(t *testing.T) {
+               dir := copyToTemp(t, errorReportingProjDir)
+               out := errorReportingExpectFail(t, dir,
+                       []string{"does not specify bsp.downloadscript"}, 
"load", "app")
+               if strings.Contains(out, "Loading app image") {
+                       t.Errorf("load reported as started\n%s", out)
+               }
+       })
+
+       t.Run("debug", func(t *testing.T) {
+               dir := copyToTemp(t, errorReportingProjDir)
+               errorReportingExpectFail(t, dir,
+                       []string{"does not specify bsp.debugscript"}, "debug", 
"app")
+       })
+}

Reply via email to