Skip to content

Failuer to parse slog.Level with flag redefined #36

@head-gardener

Description

@head-gardener

Attempting to fill fields from a structure containing slog.Level, which is a redefinition of int, panics with flag: redefined: <flag-name> at runtime:

/tmp/go-build2849440774/b001/exe/test flag redefined: level
panic: /tmp/go-build2849440774/b001/exe/test flag redefined: level

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000bc000, {0x53f268, 0xc0000900a0}, {0xc0000141e0, 0x5}, {0x0, 0x0})
        /nix/store/j9hk9x78z301jqldfyvw72z24vb992qi-go-1.22.6/share/go/src/flag/flag.go:1028 +0x37d
flag.(*FlagSet).Func(...)
        /nix/store/j9hk9x78z301jqldfyvw72z24vb992qi-go-1.22.6/share/go/src/flag/flag.go:980
github.com/itzg/go-flagsfiller.(*FlagSetFiller).processCustom(0xc0000141e0?, {0x504a20, 0xc0000141d0}, 0x51bca8, 0x0?, {0x0?, 0xc000014210?}, 0xc0000bc000, {0xc0000141e0, 0x5}, ...)
        /home/hunter/go/pkg/mod/github.com/itzg/go-flagsfiller@v1.14.0/flagset.go:621 +0x292
github.com/itzg/go-flagsfiller.(*FlagSetFiller).processInt(0x0?, {0x504a20?, 0xc0000141d0?}, 0xfe?, {0x0?, 0xc0000141d0?}, 0x20a20?, {0xc0000141e0?, 0x5e8420?}, {0x0, ...}, ...)
        /home/hunter/go/pkg/mod/github.com/itzg/go-flagsfiller@v1.14.0/flagset.go:410 +0x1cd
github.com/itzg/go-flagsfiller.(*FlagSetFiller).processField(0xc000074040, 0xc0000bc000, {0x504a20, 0xc0000141d0}, {0x4e46fb, 0x5}, {0x540c60, 0x4faf60}, {0x0, 0x0})
        /home/hunter/go/pkg/mod/github.com/itzg/go-flagsfiller@v1.14.0/flagset.go:224 +0x759
github.com/itzg/go-flagsfiller.(*FlagSetFiller).walkFields.func1({{0x4e46fb, 0x5}, {0x0, 0x0}, {0x540c60, 0x4faf60}, {0x0, 0x0}, 0x0, {0xc0000141d8, ...}, ...}, ...)
        /home/hunter/go/pkg/mod/github.com/itzg/go-flagsfiller@v1.14.0/flagset.go:98 +0x1b3
github.com/itzg/go-flagsfiller.(*FlagSetFiller).walkFields(0xc000074040, 0xc0000bc000, {0x0?, 0x7f23091f3108?}, {0x4f8b20?, 0xc0000141d0?, 0xc000074040?}, {0x540c60, 0x4f8b20})
        /home/hunter/go/pkg/mod/github.com/itzg/go-flagsfiller@v1.14.0/flagset.go:156 +0x6fc
github.com/itzg/go-flagsfiller.(*FlagSetFiller).Fill(0xc000074040, 0xc0000bc000, {0x4ee0a0?, 0xc0000141d0?})
        /home/hunter/go/pkg/mod/github.com/itzg/go-flagsfiller@v1.14.0/flagset.go:54 +0x1de
main.main()
        /tmp/tmp.dPTGjwn3vd/main.go:16 +0x47
exit status 2

Minimal example:

package main

import (
	"flag"
	"log/slog"

	"github.com/itzg/go-flagsfiller"
)

func main() {
	var args struct {
		Level slog.Level
	}
	flagsfiller.New().Fill(flag.CommandLine, &args)
}

I'm new to go so sorry in advance if i missed some debug info.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions