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

    newt/mfg: Treat missing mfg.meta as no meta
    
    mfg.meta is optional, but GetValStringMap() returns an empty map, not
    nil, if the key is absent. An mfg.yml without mfg.meta thus failed
    with a confusing 'meta map missing required field "area"' error.
    Decode meta only if mfg.meta is not empty.
    
    Assisted-by: Claude:claude-opus-5-5
---
 newt/mfg/decode.go           |  2 +-
 newt/mfg/decode_meta_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/newt/mfg/decode.go b/newt/mfg/decode.go
index 392395f6..90148ec3 100644
--- a/newt/mfg/decode.go
+++ b/newt/mfg/decode.go
@@ -366,7 +366,7 @@ func decodeMfg(yc ycfg.YCfg) (DecodedMfg, error) {
        yamlMeta, err := yc.GetValStringMap("mfg.meta", nil)
        util.OneTimeWarningError(err)
 
-       if yamlMeta != nil {
+       if len(yamlMeta) > 0 {
                meta, err := decodeMeta(yamlMeta)
                if err != nil {
                        return dm, err
diff --git a/newt/mfg/decode_meta_test.go b/newt/mfg/decode_meta_test.go
new file mode 100644
index 00000000..1409c864
--- /dev/null
+++ b/newt/mfg/decode_meta_test.go
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package mfg
+
+import (
+       "testing"
+
+       "mynewt.apache.org/newt/newt/ycfg"
+)
+
+// mfg.meta is optional; an mfg.yml without it must decode without meta.
+func TestDecodeMfgNoMeta(t *testing.T) {
+       yc := ycfg.NewYCfg("mfg.yml")
+       if err := yc.Replace("mfg.bsp", "hw/bsp/sim"); err != nil {
+               t.Fatal(err)
+       }
+
+       dm, err := decodeMfg(yc)
+       if err != nil {
+               t.Fatalf("unexpected error: %s", err)
+       }
+       if dm.Meta != nil {
+               t.Errorf("unexpected meta: %+v", *dm.Meta)
+       }
+}

Reply via email to