manifoldco / promptui

Interactive prompt for command-line applications
https://www.manifold.co
BSD 3-Clause "New" or "Revised" License
6.07k stars 336 forks source link

Process Panics Whenever Running Prompt #158

Open nisdas opened 4 years ago

nisdas commented 4 years ago

This happens quite often, whenever running a prompt. Ex:

            prompt := promptui.Prompt{
            Label:    "randomtext",
            Mask:     '*',
        }

        receivedText, err = prompt.Run()
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0xfd1bde]

goroutine 170 [running]:
github.com/manifoldco/promptui.(*Prompt).Run.func2(0x24c38b8, 0x0, 0x0, 0x0, 0xd, 0xc000314e50, 0x24c38b8, 0x0, 0xc000314e50, 0x162bf40)
        external/com_github_manifoldco_promptui/prompt.go:166 +0x3de
github.com/chzyer/readline.(*DumpListener).OnChange(0xc000196aa8, 0x24c38b8, 0x0, 0x0, 0x0, 0xd, 0x0, 0x0, 0x0, 0x0, ...)
        external/com_github_chzyer_readline/operation.go:516 +0x63
github.com/chzyer/readline.(*Operation).ioloop(0xc000deb500)
        external/com_github_chzyer_readline/operation.go:339 +0x44d
created by github.com/chzyer/readline.NewOperation
jessequinn commented 4 years ago

I have also experienced this.

The following example

        prompt = promptui.Prompt{
            Label: "Quantos agentes precisam ser instalados",
            Validate: func(input string) error {
                _, err := strconv.ParseInt(input, 0, 64)
                if err != nil {
                    return errors.New("Por favor digite um número inteiro")
                }
                return nil
            },
        }

        serverCountString, err := prompt.Run()
        if err != nil {
            return &ce.Error{Arg: 1, Message: err.Error()}
        }
jessequinn commented 4 years ago

I believe the problem only occurs when trying to reuse the prompt variable. for me it is resolved.