Skip to content

panic: reflect.Set: value of type interface {} is not assignable to type []string #601

@bep

Description

@bep

I have ported the TOML config in hugoreleaser to YAML using this YAML library. The primary motivation behind this was to be able to use YAML anchors/aliases get Hugo's release config a little more manageable.

Unfortunately my setup crashes:

See https://go.dev/play/p/lNf3br5S0sF

package main

import (
	"strings"

	yaml "github.com/goccy/go-yaml"
)

type Build struct {
	Definitions   map[string]any `json:"definitions"`
	BuildSettings BuildSettings  `json:"build_settings"`
}

type BuildSettings struct {
	Binary  string   `json:"binary"`
	Flags   []string `json:"flags"`
	Env     []string `json:"env"`
	Ldflags string   `json:"ldflags"`
}

func main() {
	config := `
definitions:
  myenv: &my_env
    - VAR1=1
    - VAR2=2
build_settings:
  binary: hugoreleaser
  flags:
    - -buildmode
    - exe
  env: *my_env
  ldflags: "-s -w -X main.tag=${HUGORELEASER_TAG}"

`
	d := yaml.NewDecoder(strings.NewReader(config),
		yaml.DisallowUnknownField(),
	)

	var cfg Build

	err := d.Decode(&cfg)
	if err != nil {
		panic(err)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions