diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-05 22:22:46 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-05 22:23:09 +0800 |
commit | 272534584376c81116db5199fd2e4216e3698192 (patch) | |
tree | 72fdac8c31f0d92e77f407f3cf7f9991cdb8724c /internal/scfg/unmarshal.go | |
parent | Move scfg into the repo and don't error out on unknown fields (diff) | |
download | forge-0.1.25.tar.gz forge-0.1.25.tar.zst forge-0.1.25.zip |
scfg: Error out when required directives are missingv0.1.25
Diffstat (limited to 'internal/scfg/unmarshal.go')
-rw-r--r-- | internal/scfg/unmarshal.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/scfg/unmarshal.go b/internal/scfg/unmarshal.go index 19f3dae..e9e1a52 100644 --- a/internal/scfg/unmarshal.go +++ b/internal/scfg/unmarshal.go @@ -107,12 +107,15 @@ func (dec *Decoder) unmarshalBlock(block Block, v reflect.Value) error { } v.SetMapIndex(reflect.ValueOf(name), mv) } + case reflect.Struct: si, err := getStructInfo(t) if err != nil { return err } + seen := make(map[int]bool) + for name, dirs := range dirsByName { fieldIndex, ok := si.children[name] if !ok { @@ -123,7 +126,18 @@ func (dec *Decoder) unmarshalBlock(block Block, v reflect.Value) error { if err := dec.unmarshalDirectiveList(dirs, fv); err != nil { return err } + seen[fieldIndex] = true + } + + for name, fieldIndex := range si.children { + if fieldIndex == si.param { + continue + } + if _, ok := seen[fieldIndex]; !ok { + return fmt.Errorf("scfg: missing required directive %q", name) + } } + default: return fmt.Errorf("scfg: unsupported type for unmarshaling blocks: %v", t) } |