flow-cli icon indicating copy to clipboard operation
flow-cli copied to clipboard

Crash detected when deploying contracts with array init args

Open sisyphusSmiling opened this issue 1 year ago • 2 comments

Problem

When using flow accounts add-contract command to deploy a contract with an array of values as init parameters, CLI crashes. However, passing an array to scripts seems to work just find.

Steps to Reproduce

Try deploying this simple contract:

access(all) contract Foo {

    access(all) var bars: [Int]

    access(all) fun foo(i: Int): Int {
        return (self.bars.length - 1) >= i ? self.bars[i] : 0
    }

    init(bars: [Int]) {
        self.bars = bars
    }
}

with the command:

flow accounts add-contract ./cadence/contracts/Foo.cdc '[1]'

And note the crash output

❌ Crash detected!

✔ No

Please help us improve the Flow CLI by opening an issue on https://github.com/onflow/flow-cli/issues,
and pasting the output as well as a description of the actions you took that resulted in this crash.

runtime error: invalid memory address or nil pointer dereference
[] []
map[device:map[arch:arm64 num_cpu:8] os:map[name:darwin] runtime:map[go_maxprocs:8 go_numcgocalls:6 go_numroutines:11 name:go version:go1.21.3]]
goroutine 1 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x64
github.com/onflow/flow-cli/internal/command.initCrashReporting.func1(0x1400023fb80, 0x14000b27020)
	github.com/onflow/flow-cli/internal/command/command.go:314 +0x1c8
github.com/getsentry/sentry-go.(*Client).processEvent(0x1400070b2c0, 0x1400023fb80, 0x14000b27020, {0x10294aea0, 0x14000414ea0})
	github.com/getsentry/[email protected]/client.go:631 +0x228
github.com/getsentry/sentry-go.(*Client).CaptureEvent(...)
	github.com/getsentry/[email protected]/client.go:447
github.com/getsentry/sentry-go.(*Client).RecoverWithContext(0x60?, {0x0?, 0x0}, {0x1025d9be0?, 0x103b64da0?}, 0x100e9306c?, {0x10294aea0, 0x14000414ea0})
	github.com/getsentry/[email protected]/client.go:498 +0x1d4
github.com/getsentry/sentry-go.(*Client).Recover(0x0?, {0x1025d9be0?, 0x103b64da0?}, 0x0?, {0x10294aea0?, 0x14000414ea0?})
	github.com/getsentry/[email protected]/client.go:462 +0x80
github.com/getsentry/sentry-go.(*Hub).Recover(0x14000a28d58?, {0x1025d9be0?, 0x103b64da0?})
	github.com/getsentry/[email protected]/hub.go:330 +0xc0
github.com/getsentry/sentry-go.Recover()
	github.com/getsentry/[email protected]/sentry.go:68 +0x40
panic({0x1025d9be0?, 0x103b64da0?})
	runtime/panic.go:914 +0x218
github.com/onflow/flow-cli/flowkit/transactions.addAccountContractWithArgs(0x140001859a0, {{0x14000a42ba8?, 0xe1?}, {0x140008d41e0?, 0x1?}}, {0x14000a06910, 0x1, 0x1b?})
	github.com/onflow/flow-cli/[email protected]/transactions/transaction.go:121 +0x2e0
github.com/onflow/flow-cli/flowkit/transactions.NewAddAccountContract(...)
	github.com/onflow/flow-cli/[email protected]/transactions/transaction.go:82
github.com/onflow/flow-cli/flowkit.(*Flowkit).AddContract(0x14000159c20, {0x2e1?, 0x16f68362b?}, 0x140001859a0, {{0x14000698300, 0xe1, 0x2e1}, {0x14000a06910, 0x1, 0x1}, ...}, ...)
	github.com/onflow/flow-cli/[email protected]/flowkit.go:299 +0x224
github.com/onflow/flow-cli/internal/accounts.init.deployContract.func3({0x140001b33e0, 0x2, 0x2}, {{0x0, 0x0}, {0x101e0ad73, 0x4}, {0x0, 0x0}, {0x0, ...}, ...}, ...)
	github.com/onflow/flow-cli/internal/accounts/contract-add.go:93 +0x2f0
github.com/onflow/flow-cli/internal/command.Command.AddToParent.func1(0x1400077c500?, {0x140001b33e0, 0x2, 0x2})
	github.com/onflow/flow-cli/internal/command/command.go:141 +0x4f0
github.com/spf13/cobra.(*Command).execute(0x103b91ac0, {0x14000160030, 0x2, 0x2})
	github.com/spf13/[email protected]/command.go:944 +0x640
github.com/spf13/cobra.(*Command).ExecuteC(0x14000700f00)
	github.com/spf13/[email protected]/command.go:1068 +0x320
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:992
main.main()
	github.com/onflow/flow-cli/cmd/flow/main.go:118 +0xb48

Device Info

macOS 13.6 (22G120) Flow CLI Version: v1.5.0

sisyphusSmiling avatar Oct 31 '23 16:10 sisyphusSmiling