fix: Map decode issues #20

Merged
onlyati merged 2 commits from fix/map-decode-panics-and-duplicate-sections into main 2026-09-14 20:00:29 +00:00
Owner

Resolve #15 #16

Resolve #15 #16
decodeFileNode indexed sections by name with a plain map assignment
(sectionMap[cleanName] = sec), so when a unit file had more than one
section with the same name, only the last occurrence's assignments
ever reached the destination struct field, silently dropping the
earlier ones. Map-shaped decode targets already merged assignments
from same-named sections; struct decode now does the same by
accumulating each field's assignments across every matching section
before decoding them, and decodeSectionNode takes that merged
assignment list directly instead of a single *SectionNode.
fix: decode into typed map targets instead of panicking
All checks were successful
ci/woodpecker/pr/pr_check Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
16a3ab3f5a
decodeFileToMapReflect always built an untyped map[string]any tree
and copied it straight into the destination map with SetMapIndex, so
any target shape other than exactly map[string]any (e.g.
map[string]string, map[string]int, or map[string]map[string]string)
panicked with an unhandled reflect.Value.SetMapIndex type mismatch
instead of Unmarshal returning an error. Duplicate keys promoted to
[]string hit the same panic whenever the destination expected a
scalar.

Rewrite it to inspect the destination's element type: interface{}
keeps the existing dynamic map[string]any behavior, map element types
now decode one inner map per section (reusing setFieldValue for
per-value conversion, and reusing the same duplicate-key error struct
decoding already returns), and any other element type returns a
descriptive error instead of reaching the panic.
onlyati changed title from fix/map-decode-panics-and-duplicate-sections to fix: Map decode issues 2026-09-14 19:58:06 +00:00
onlyati deleted branch fix/map-decode-panics-and-duplicate-sections 2026-09-14 20:00:29 +00:00
onlyati referenced this pull request from a commit 2026-09-14 20:00:29 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pandora/systemd-file.gopack!20
No description provided.