Marshaling json when returning AnyStruct from a script
Open
@chasefleming is already working on this.
Since Dec 13, 2023.
Feedback
- Dominant language
- Go
- Stars
- 209
- Forks
- 87
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 3
Description
Problem
Returning AnyStruct and getting json output used to work, now i get this error:
output from error
failed to encode value: unsupported type: cadence.TypeID, A.097bafa4e0b48eef.FIND.LeaseCollectionPublic
[] []
map[device:map[arch:arm64 num_cpu:8] os:map[name:darwin] runtime:map[go_maxprocs:8 go_numcgocalls:12 go_numroutines:19 name:go version:go1.21.4]]
goroutine 1 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:24 +0x64
github.com/onflow/flow-cli/internal/command.initCrashReporting.func1(0x14000233b80, 0x14000ba7ec0)
github.com/onflow/flow-cli/internal/command/command.go:314 +0x1c8
github.com/getsentry/sentry-go.(*Client).processEvent(0x14000957a40, 0x14000233b80, 0x14000ba7ec0, {0x103179ec0, 0x1400052a7e0})
github.com/getsentry/sentry-go@v0.25.0/client.go:631 +0x228
github.com/getsentry/sentry-go.(*Client).CaptureEvent(...)
github.com/getsentry/sentry-go@v0.25.0/client.go:447
github.com/getsentry/sentry-go.(*Client).RecoverWithContext(0x60?, {0x0?, 0x0}, {0x102e21e60?, 0x1400021b180?}, 0x1016a521c?, {0x103179ec0, 0x1400052a7e0})
github.com/getsentry/sentry-go@v0.25.0/client.go:498 +0x1d4
github.com/getsentry/sentry-go.(*Client).Recover(0x10?, {0x102e21e60?, 0x1400021b180?}, 0x100f7da8c?, {0x103179ec0?, 0x1400052a7e0?})
github.com/getsentry/sentry-go@v0.25.0/client.go:462 +0x80
github.com/getsentry/sentry-go.(*Hub).Recover(0x14000a416a8?, {0x102e21e60?, 0x1400021b180?})
github.com/getsentry/sentry-go@v0.25.0/hub.go:330 +0xc0
github.com/getsentry/sentry-go.Recover()
github.com/getsentry/sentry-go@v0.25.0/sentry.go:68 +0x40
panic({0x102e21e60?, 0x1400021b180?})
runtime/panic.go:914 +0x218
github.com/onflow/cadence/encoding/json.MustEncode(...)
github.com/onflow/cadence@v0.42.5/encoding/json/encode.go:61
github.com/onflow/flow-cli/internal/scripts.(*scriptResult).JSON(0x16ee90f50?)
github.com/onflow/flow-cli/internal/scripts/scripts.go:50 +0x5c
github.com/onflow/flow-cli/internal/command.formatResult({0x10318ccd0, 0x14000b83e10}, {0x0?, 0x0?}, {0x16ee90f50?, 0x0?})
github.com/onflow/flow-cli/internal/command/result.go:75 +0xc8
github.com/onflow/flow-cli/internal/command.Command.AddToParent.func1(0x140009d0a00?, {0x1400054cfc0, 0x3, 0x7})
github.com/onflow/flow-cli/internal/command/command.go:157 +0x5dc
github.com/spf13/cobra.(*Command).execute(0x1042d4320, {0x140001be0d0, 0x7, 0x7})
github.com/spf13/cobra@v1.8.0/command.go:987 +0x814
github.com/spf13/cobra.(*Command).ExecuteC(0x140008d0900)
github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
github.com/onflow/flow-cli/cmd/flow/main.go:119 +0xb6c
Steps to Reproduce
flow version: v1.8.0
script
pub fun main(user: String, path: String) : AnyStruct{
let address=FIND.resolve(user) ?? panic("could not find user")
let account=getAuthAccount(address)
return account.borrow<&AnyResource>(from:StoragePath(identifier:path)!)!
}
cli-invocation flow scripts execute scripts/storage.cdc -n mainnet bjartek findBids -o json
Acceptance Criteria
It should show me json
Context
Just trying to make a small too to browse storage from terminal :)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.