wails icon indicating copy to clipboard operation
wails copied to clipboard

Bind panic

Open monopolly opened this issue 3 years ago • 8 comments

Description

Sorry guys, another issue) There is an issue about a go function's bind.

Here is a bind function

func (a *App) Bool(k string, v ...bool) (res bool) {
//...something here
}

here is a simple js call - its the right call of go function

Bool('key', true)

in Go I just ignore ...bool value but wails don't: panic: reflect: cannot use []bool as type bool in Call

To Reproduce

go

func (a *App) Bool(k string, v ...bool) (res bool) {
   if v != nil{
     return true
   }
  return false
}

js

let res = await Bool('key', true)

Expected behaviour

wails have to understand that bool is valid value for a go "...bool" slice

Screenshots

panic: reflect: cannot use []bool as type bool in Call

Attempted Fixes

No response

System Details

System
------
OS:		MacOS
Version: 	12.4
ID:		199506
Go Version:	go1.18
Platform:	darwin
Architecture:	amd64

Wails
------
Version: 	v2.0.0-beta.38

Dependency			Package Name	Status		Version
----------			------------	------		-------
xcode command line tools 	N/A		Installed	2395
npm 				N/A		Installed	8.11.0
*upx 				N/A		Available	
*nsis 				N/A		Installed	v3.08

* - Optional Dependency

Diagnosis
---------
Your system is ready for Wails development!
Optional package(s) installation details: 
  - upx : Available at https://upx.github.io/



If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

No response

monopolly avatar Jul 20 '22 21:07 monopolly

Thanks for reporting this. Just checking... If you name the function "Zool" does it still panic?

leaanthony avatar Jul 20 '22 21:07 leaanthony

no no, it doest't matter whats the name of the function

if go function has a lazy slice param, wails have to understand it

monopolly avatar Jul 20 '22 21:07 monopolly

There's a good chance we aren't handling varargs. If you get rid of the 3 dots, does it still panic?

leaanthony avatar Jul 20 '22 21:07 leaanthony

no if I use simple []bool all is ok, just for lazy slices.

monopolly avatar Jul 20 '22 21:07 monopolly

"lazy slices" I just call them that) ...some

monopolly avatar Jul 20 '22 21:07 monopolly

https://wails.io/docs/guides/troubleshooting#cannot-call-backend-method-from-frontend-with-variadic-arguments

At the very least we should have a better error message

leaanthony avatar Jul 20 '22 21:07 leaanthony

my bet sorry)

monopolly avatar Jul 20 '22 21:07 monopolly

I mean, we shouldn't panic, but show a better message 🤣

leaanthony avatar Jul 20 '22 21:07 leaanthony

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 02 '22 02:11 stale[bot]