Skip to content

Conversation

@coryb
Copy link
Owner

@coryb coryb commented Jun 19, 2025

  • fix merging for two differnt Option types, select the type that both merge types are assignable to (ie Option[string] vs Option[any], Option[any] will be chosen).
  • preserve tags when merging fields
  • prefer figtree:"name=value" tag for field names.
  • prevent duplicate conflicts between yaml names and struct field names.

* prefer `figtree:"name=value"` tag for field names.
* prevent duplicate conflicts between yaml names and struct field names.
figtree.go Outdated
Comment on lines 564 to 566
case aOk && bOk:
// if both defined, pick the first one
resultTag = append(resultTag, fmt.Sprintf("%s:%q", tag, aTag))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant with case aOk below

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merged the cases

figtree.go Outdated
if prev, ok := seen[value.Name]; ok {
// we have a duplicate field name, this should not happen
// but if it does, we will just skip it
fmt.Fprintf(os.Stderr, "Duplicate field name %q in merge struct.\n\tOld: %s %s `%s`\n\tNew: %s %s `%s`\n", value.Name, prev.Name, prev.Type.String(), prev.Tag, value.Name, value.Type.String(), value.Tag)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this debugging code? Not sure we want figtree to print to os.Stderr on its own accord. I'd suggest either:

  • A panic if this shouldn't be possible to trigger
  • Silently ignored if it can happen but isn't actionable
  • Pass in a logger if it's something we want to bubble up non-fatally

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up converting these to panics. The reflect.MakeStruct call will panic below if we have duplicate fields, so better to panic here with slightly friendlier output.

figtree.go Outdated
if prev, ok := yamlSeen[yamlName]; yamlName != "" && ok {
// we have a duplicate field name, this should not happen
// but if it does, we will just skip it
fmt.Fprintf(os.Stderr, "Duplicate YAML tag %q in merge struct.\n\tOld: %s %s `%s`\n\tNew: %s %s `%s`\n", yamlName, prev.Name, prev.Type.String(), prev.Tag, value.Name, value.Type.String(), value.Tag)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern about printing to stderr

@coryb coryb merged commit 7a28eb5 into main Jun 20, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants