The app panics while parsing args
olebedev opened this issue · 2 comments
olebedev commented
The content of the main file:
func main() {
swarm := &swarmdb.App{}
app := cli.App("swarm", "0.1.0.draft")
app.Command("init", "Initialize a new databse", func(cmd *cli.Cmd) {
r := cmd.StringArg("REPLICA", "default", "replica UUID")
cmd.Action = func() {
err := swarm.Init(r)
if err != nil {
swarm.Logger.WithError(err).Error("initialize a new database")
os.Exit(1)
}
}
})
app.Run(os.Args)
}
I ran the tool with swarm init test
and have got a panic:
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x40dd1e6]
goroutine 1 [running]:
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420010ab0, 0x429a760, 0x447e640)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:29 +0x146
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420010ba0, 0x429a760, 0x447e640)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:21 +0x12e
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420010e70, 0x429a760, 0x447e640)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:21 +0x12e
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).callDo.func1(0xc420010ea0, 0x0, 0x0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:42 +0x4c
panic(0x429a760, 0x447e640)
/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
github.com/olebedev/swarmdb/vendor/github.com/apex/log.(*Logger).log(0x0, 0x3, 0xc4200aa310, 0x42e6f4c, 0x19)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/apex/log/logger.go:142 +0x26
github.com/olebedev/swarmdb/vendor/github.com/apex/log.(*Entry).Error(0xc4200aa310, 0x42e6f4c, 0x19)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/apex/log/entry.go:96 +0x50
main.main.func1.1()
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/cmd/swarm/main.go:31 +0xc0
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).callDo(0xc420010ea0, 0x0, 0x0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:45 +0x70
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420010ea0, 0x0, 0x0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:17 +0xb3
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420010e40, 0x0, 0x0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:21 +0x12e
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420010b70, 0x0, 0x0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:21 +0x12e
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*step).run(0xc420051ee0, 0x0, 0x0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/flow.go:21 +0x12e
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*Cmd).parse(0xc4200b2200, 0xc4200100e0, 0x1, 0x1, 0xc420051ee0, 0xc420010b70, 0xc420010ba0, 0xc42006e168, 0xc42006e120)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/commands.go:473 +0x529
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*Cmd).parse(0xc4200b2100, 0xc4200100d0, 0x2, 0x2, 0xc420051ee0, 0xc420051ee0, 0xc420010ab0, 0xc4200b2101, 0xc420010ab0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/commands.go:487 +0x7ad
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*Cli).parse(0xc420051f60, 0xc4200100d0, 0x2, 0x2, 0xc420051ee0, 0xc420051ee0, 0xc420010ab0, 0x1, 0x1)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/cli.go:73 +0x102
github.com/olebedev/swarmdb/vendor/github.com/jawher/mow%2ecli.(*Cli).Run(0xc420051f60, 0xc4200100c0, 0x3, 0x3, 0x18, 0xc4200426c0)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/jawher/mow.cli/cli.go:102 +0x134
main.main()
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/cmd/swarm/main.go:37 +0x20b
Why this could happened?
Thanks
jawher commented
Hi,
The panic trace points to a panic raised in:
github.com/olebedev/swarmdb/vendor/github.com/apex/log.(*Logger).log(0x0, 0x3, 0xc4200aa310, 0x42e6f4c, 0x19)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/apex/log/logger.go:142 +0x26
github.com/olebedev/swarmdb/vendor/github.com/apex/log.(*Entry).Error(0xc4200aa310, 0x42e6f4c, 0x19)
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/vendor/github.com/apex/log/entry.go:96 +0x50
main.main.func1.1()
/usr/local/Cellar/go/workspace/src/github.com/olebedev/swarmdb/cmd/swarm/main.go:31 +0xc0
I couldn't look further into this since swarmdb is apparently a private repo.
As far as I can tell, the issue is not in mow.cli
but further down the chain.
The following code works flawlessly:
func main() {
app := cli.App("swarm", "0.1.0.draft")
app.Command("init", "Initialize a new databse", func(cmd *cli.Cmd) {
r := cmd.StringArg("REPLICA", "default", "replica UUID")
cmd.Action = func() {
fmt.Printf("r=%s\n", *r)
}
})
app.Run(os.Args)
}
olebedev commented
Oh, sorry it's my bad
I am closing this. Thank you.