Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic when the only result is a nil error #63

Merged
merged 1 commit into from
May 22, 2019
Merged

Fix panic when the only result is a nil error #63

merged 1 commit into from
May 22, 2019

Conversation

velut
Copy link
Contributor

@velut velut commented May 22, 2019

This fixes the panic that happens when a bound function having only one error-like return value returns nil.

An example of the issue is the following

package main

import (
	"github.com/zserge/lorca"
)

func oneNilErrorResult() error {
	return nil
}

func main() {
	ui, _ := lorca.New("", "", 480, 320)
	defer ui.Close()

	ui.Bind("oneNilErrorResult", oneNilErrorResult)

	ui.Eval("oneNilErrorResult()") // Panic!

	<-ui.Done()
}

which causes the following error

panic: interface conversion: interface is nil, not error

goroutine 23 [running]:
github.com/zserge/lorca.(*ui).Bind.func1(0xa59470, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        github.com/zserge/lorca@v0.1.7/ui.go:142 +0x711
github.com/zserge/lorca.(*chrome).readLoop.func2(0xc000158900, 0xc0001caf90, 0x7a2430, 0xc0000e40c0, 0xc0001c2b40)
        github.com/zserge/lorca@v0.1.7/chrome.go:289 +0x65
created by github.com/zserge/lorca.(*chrome).readLoop
        github.com/zserge/lorca@v0.1.7/chrome.go:287 +0x95e
exit status 2

This fixes the panic that happens when a bound function
having only one error-like return value returns nil.

This also adds tests for different bindable functions.
@zserge zserge merged commit de29b2b into zserge:master May 22, 2019
@velut velut mentioned this pull request Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants