8000 `dasel put -t json -s 'array.[]' -v "{…}"` to a TOML file crashes dasel · Issue #282 · TomWright/dasel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
dasel put -t json -s 'array.[]' -v "{…}" to a TOML file crashes dasel #282
Open
@jakubadamw

Description

@jakubadamw

Describe the bug
dasel put fails to write more than one complex element (of type JSON, which is apparently how one denotes an object regardless of the target format) to an array in a TOML file.

To Reproduce
Steps to reproduce the behavior:

$ touch test.toml
$ dasel put -f test.toml -t json -s "array.[]" -v "{ \"key\": \"value\" }"
$ cat test.toml
array = [{ key = "value" }]
$ dasel put -f test.toml -t json -s "array.[]" -v "{ \"key\": \"value\" }"
panic: reflect.Set: value of type []interface {} is not assignable to type []map[string]interface {}

goroutine 1 [running]:
reflect.Value.assignTo({0x104b89c80?, 0x1400012d5d8?, 0x104ba5ea0?}, {0x104a0a05d, 0xb}, 0x104b89ec0, 0x0)
        reflect/value.go:3145 +0x214
reflect.Value.Set({0x104b89ec0?, 0x1400012d170?, 0x94?}, {0x104b89c80?, 0x1400012d5d8?, 0x140003562d0?})
        reflect/value.go:2160 +0xc8
github.com/tomwright/dasel.Value.Append({{0x104b9eba0, 0x140002e9e50, 0x94}, 0x14000328540, 0x140003285b0, 0x140003562d0})
        github.com/tomwright/dasel/value.go:239 +0x17c
github.com/tomwright/dasel.glob..func3(0xf000000000000006?, 0x16?, {0x104faf9c8?, 0x14000356390?, 0x140002dae20?})
        github.com/tomwright/dasel/func_append.go:26 +0x25c
github.com/tomwright/dasel.BasicFunction.Run(...)
        github.com/tomwright/dasel/func.go:140
github.com/tomwright/dasel.(*Step).execute(0x1400014e960)
        github.com/tomwright/dasel/step.go:30 +0x5c
github.com/tomwright/dasel.(*Context).Next(0x14000275300)
        github.com/tomwright/dasel/context.go:225 +0x1cc
github.com/tomwright/dasel.(*Context).Run(0x104be5480?)
        github.com/tomwright/dasel/context.go:193 +0x34
github.com/tomwright/dasel.Put({0x104be5480, 0x14000356180}, {0x16b8cb9aa, 0x8}, {0x104be5480?, 0x14000356150?})
        github.com/tomwright/dasel/context.go:128 +0xa0
github.com/tomwright/dasel/internal/command.runPutCommand(0x14000331cc8, 0x1049e0ca7?)
        github.com/tomwright/dasel/internal/command/put.go:132 +0x4ac
github.com/tomwright/dasel/internal/command.putRunE(0x14000338300?, {0x14000275200, 0x0, 0x8?})
        github.com/tomwright/dasel/internal/command/put.go:83 +0x304
github.com/spf13/cobra.(*Command).execute(0x14000338300, {0x14000275180, 0x8, 0x8})
        github.com/spf13/cobra@v1.6.1/command.go:916 +0x5c8
github.com/spf13/cobra.(*Command).ExecuteC(0x14000338000)
        github.com/spf13/cobra@v1.6.1/command.go:1044 +0x35c
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.6.1/command.go:968
main.main()
        github.com/tomwright/dasel/cmd/dasel/main.go:10 +0x24
$ dasel put -f test.toml -t json -s "array.[]" -v 123
panic: reflect.Set: value of type []interface {} is not assignable to type []map[string]interface {}

goroutine 1 [running]:
reflect.Value.assignTo({0x1055fdc80?, 0x1400012d578?, 0x105619ea0?}, {0x10547e05d, 0xb}, 0x1055fdec0, 0x0)
        reflect/value.go:3145 +0x214
reflect.Value.Set({0x1055fdec0?, 0x1400012d110?, 0x94?}, {0x1055fdc80?, 0x1400012d578?, 0x140002d62a0?})
        reflect/value.go:2160 +0xc8
github.com/tomwright/dasel.Value.Append({{0x105612ba0, 0x14000269e20, 0x94}, 0x140002aa540, 0x140002aa5b0, 0x140002d62a0})
        github.com/tomwright/dasel/value.go:239 +0x17c
github.com/tomwright/dasel.glob..func3(0xef00000000000006?, 0x16?, {0x105a239c8?, 0x140002d6360?, 0x1400025ade0?})
        github.com/tomwright/dasel/func_append.go:26 +0x25c
github.com/tomwright/dasel.BasicFunction.Run(...)
        github.com/tomwright/dasel/func.go:140
github.com/tomwright/dasel.(*Step).execute(0x1400010e9b0)
        github.com/tomwright/dasel/step.go:30 +0x5c
github.com/tomwright/dasel.(*Context).Next(0x140001f3300)
        github.com/tomwright/dasel/context.go:225 +0x1cc
github.com/tomwright/dasel.(*Context).Run(0x105659480?)
        github.com/tomwright/dasel/context.go:193 +0x34
github.com/tomwright/dasel.Put({0x105659480, 0x140002d6150}, {0x16ae579ba, 0x8}, {0x105659480?, 0x140002d6120?})
        github.com/tomwright/dasel/context.go:128 +0xa0
github.com/tomwright/dasel/internal/command.runPutCommand(0x140002b3cc8, 0x105454ca7?)
        github.com/tomwright/dasel/internal/command/put.go:132 +0x4ac
github.com/tomwright/dasel/internal/command.putRunE(0x140002ba300?, {0x140001f3200, 0x0, 0x8?})
        github.com/tomwright/dasel/internal/command/put.go:83 +0x304
github.com/spf13/cobra.(*Command).execute(0x140002ba300, {0x140001f3180, 0x8, 0x8})
        github.com/spf13/cobra@v1.6.1/command.go:916 +0x5c8
github.com/spf13/cobra.(*Command).ExecuteC(0x140002ba000)
        github.com/spf13/cobra@v1.6.1/command.go:1044 +0x35c
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.6.1/command.go:968
main.main()
        github.com/tomwright/dasel/cmd/dasel/main.go:10 +0x24
$ dasel put -f test.toml -t json -s "array2.[]" -v 123
$ dasel put -f test.toml -t json -s "array2.[]" -v "{ \"key\": \"value\" }"
$ dasel put -f test.toml -t json -s "array2.[]" -v 1234
$ cat test.toml
array2 = [123.0, { key = "value" }, 1234.0]

[[array]]
  key = "value"

Expected behavior
The above commands should succeed.

Desktop (please complete the following information):

$ dasel -v
dasel version 2.0.2

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

      0