[GH-ISSUE #1077] applicaton crash #781

Closed
opened 2026-03-04 01:07:42 +03:00 by kerem · 2 comments
Owner

Originally created by @natxo on GitHub (Mar 5, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1077

hi,

with this code:

package main

import (
	"errors"
	"fmt"
	"kk/phpipam"

	"github.com/rivo/tview"
)

var c *phpipam.Client

func main() {
	app := tview.NewApplication()

	user := tview.NewInputField().SetLabel("user name: ")
	pwd := tview.NewInputField().SetLabel("password: ").SetMaskCharacter(' ')

	tvdata := tview.NewTextView().
		SetDynamicColors(true).
		SetRegions(true).
		SetWordWrap(true)
	tvdata.SetBorder(true).SetTitle("data")

	form := tview.NewForm().
		AddFormItem(user).
		AddFormItem(pwd).
		AddButton("enter", func() {
			var err error
			c, err = connectipam(user.GetText(), pwd.GetText())
			switch err.Error() {
			case "Invalid username or password":
				fmt.Println(err.Error())
			case "Your IP has been blocked for 5 minutes because of excessive login failures":
				fmt.Println("IP bloked 5 minutes due to too many incorrect login attems")
			}
			refreshdata(tvdata, c.ServerURL)
		})

	flex := tview.NewFlex().
		AddItem(form, 0, 1, true).
		AddItem(tvdata, 0, 1, false)

	if err := app.SetRoot(flex, true).Run(); err != nil {
		panic(err)
	}

}

func refreshdata(data *tview.TextView, info string) {
	data.Clear()
	fmt.Fprintln(data, info)

}

func connectipam(user, passwd string) (client *phpipam.Client, err error) {
	config := phpipam.Config{
		Hostname:      "https://ipam.example.org/phpipam",
		Application:   "app",
		Username:      user,
		Password:      passwd,
		SSLSkipVerify: true,
	}
	client, err = config.NewClient()
	if err.Error() == "Invalid username or password" {
		return nil, errors.New("Invalid username or password")
		//return nil, err
	}
	return client, err
}

the application crashes when I enter a wrong username/password like this:

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=0x7094cf]

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1()
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/application.go:297 +0x45
panic({0x743f00?, 0xa888b0?})
/usr/lib/golang/src/runtime/panic.go:785 +0x132
main.main.func1()
/home/natxo/code/gophpipam/cmd/client.go:37 +0x16f
github.com/rivo/tview.(*Form).InputHandler.func1.(*Button).InputHandler.1(0x18?, 0x7fcd0980b368?)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/button.go:165 +0x4d
github.com/rivo/tview.(*Form).InputHandler.func1.(*Button).InputHandler.(*Box).WrapInputHandler.2(0x46861d?, 0xc000100008?)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/box.go:167 +0x50
github.com/rivo/tview.(*Form).InputHandler.func1(0xc000122fa0, 0xc0002e42c0)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/form.go:867 +0x13b
github.com/rivo/tview.(*Form).InputHandler.(*Box).WrapInputHandler.func2(0xc000164160?, 0xc000100008?)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/box.go:167 +0x50
github.com/rivo/tview.(*Flex).InputHandler.func1(0xc000122fa0, 0xc0002e42c0)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/flex.go:255 +0xd7
github.com/rivo/tview.(*Flex).InputHandler.(*Box).WrapInputHandler.func2(0xc000112ab0?, 0xc00016bd38?)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/box.go:167 +0x50
github.com/rivo/tview.(*Application).Run(0xc0001440e0)
/home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/application.go:416 +0x9a2
main.main()
/home/natxo/code/gophpipam/cmd/client.go:44 +0x71f
exit status 2

No sure exactly how to catch this. Any ideas greatly appreciated.

Originally created by @natxo on GitHub (Mar 5, 2025). Original GitHub issue: https://github.com/rivo/tview/issues/1077 hi, with this code: ``` package main import ( "errors" "fmt" "kk/phpipam" "github.com/rivo/tview" ) var c *phpipam.Client func main() { app := tview.NewApplication() user := tview.NewInputField().SetLabel("user name: ") pwd := tview.NewInputField().SetLabel("password: ").SetMaskCharacter(' ') tvdata := tview.NewTextView(). SetDynamicColors(true). SetRegions(true). SetWordWrap(true) tvdata.SetBorder(true).SetTitle("data") form := tview.NewForm(). AddFormItem(user). AddFormItem(pwd). AddButton("enter", func() { var err error c, err = connectipam(user.GetText(), pwd.GetText()) switch err.Error() { case "Invalid username or password": fmt.Println(err.Error()) case "Your IP has been blocked for 5 minutes because of excessive login failures": fmt.Println("IP bloked 5 minutes due to too many incorrect login attems") } refreshdata(tvdata, c.ServerURL) }) flex := tview.NewFlex(). AddItem(form, 0, 1, true). AddItem(tvdata, 0, 1, false) if err := app.SetRoot(flex, true).Run(); err != nil { panic(err) } } func refreshdata(data *tview.TextView, info string) { data.Clear() fmt.Fprintln(data, info) } func connectipam(user, passwd string) (client *phpipam.Client, err error) { config := phpipam.Config{ Hostname: "https://ipam.example.org/phpipam", Application: "app", Username: user, Password: passwd, SSLSkipVerify: true, } client, err = config.NewClient() if err.Error() == "Invalid username or password" { return nil, errors.New("Invalid username or password") //return nil, err } return client, err } ``` the application crashes when I enter a wrong username/password like this: 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=0x7094cf] goroutine 1 [running]: github.com/rivo/tview.(*Application).Run.func1() /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/application.go:297 +0x45 panic({0x743f00?, 0xa888b0?}) /usr/lib/golang/src/runtime/panic.go:785 +0x132 main.main.func1() /home/natxo/code/gophpipam/cmd/client.go:37 +0x16f github.com/rivo/tview.(*Form).InputHandler.func1.(*Button).InputHandler.1(0x18?, 0x7fcd0980b368?) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/button.go:165 +0x4d github.com/rivo/tview.(*Form).InputHandler.func1.(*Button).InputHandler.(*Box).WrapInputHandler.2(0x46861d?, 0xc000100008?) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/box.go:167 +0x50 github.com/rivo/tview.(*Form).InputHandler.func1(0xc000122fa0, 0xc0002e42c0) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/form.go:867 +0x13b github.com/rivo/tview.(*Form).InputHandler.(*Box).WrapInputHandler.func2(0xc000164160?, 0xc000100008?) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/box.go:167 +0x50 github.com/rivo/tview.(*Flex).InputHandler.func1(0xc000122fa0, 0xc0002e42c0) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/flex.go:255 +0xd7 github.com/rivo/tview.(*Flex).InputHandler.(*Box).WrapInputHandler.func2(0xc000112ab0?, 0xc00016bd38?) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/box.go:167 +0x50 github.com/rivo/tview.(*Application).Run(0xc0001440e0) /home/natxo/go/pkg/mod/github.com/rivo/tview@v0.0.0-20241227133733-17b7edb88c57/application.go:416 +0x9a2 main.main() /home/natxo/code/gophpipam/cmd/client.go:44 +0x71f exit status 2 No sure exactly how to catch this. Any ideas greatly appreciated.
kerem closed this issue 2026-03-04 01:07:42 +03:00
Author
Owner

@natxo commented on GitHub (Mar 6, 2025):

when debugging with dlv I see that err.Error() exactly matches "Invalid username or password" by the way.

<!-- gh-comment-id:2703362608 --> @natxo commented on GitHub (Mar 6, 2025): when debugging with dlv I see that err.Error() exactly matches "Invalid username or password" by the way.
Author
Owner

@natxo commented on GitHub (Mar 6, 2025):

ah, yes, dumb.

Sorry for the noise.

<!-- gh-comment-id:2704970389 --> @natxo commented on GitHub (Mar 6, 2025): ah, yes, dumb. Sorry for the noise.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#781
No description provided.