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

garble can't work with github.com/AlecAivazis/survey/v2 #791

Open
kkqy opened this issue Sep 7, 2023 · 1 comment
Open

garble can't work with github.com/AlecAivazis/survey/v2 #791

kkqy opened this issue Sep 7, 2023 · 1 comment
Labels
bug Something isn't working reflection

Comments

@kkqy
Copy link

kkqy commented Sep 7, 2023

What version of Garble and Go are you using?

$ garble version
mvdan.cc/garble v0.10.1

Build settings:
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS windows
         GOAMD64 v1

$ go version
go version go1.20.7 windows/amd64

What environment are you running Garble on?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\User\AppData\Local\go-build
set GOENV=C:\Users\User\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\User\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\User\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.7
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=clang
set CXX=clang++
set CGO_ENABLED=1
set GOMOD=D:\projects\test\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\User\AppData\Local\Temp\go-build2700964290=/tmp/go-build -gno-record-gcc-switches

What did you do?

  1. code here:
package main

import (
	"fmt"

	"github.com/AlecAivazis/survey/v2"
)

func broken() {
	var input string
	err := survey.AskOne(&survey.Select{
		Message: "please choose:",
		Options: []string{"Option1", "Option2"},
	}, &input)

	if err != nil {
		// crash here
		panic(err)
	}
	fmt.Println(input)
}
func main() {
	broken()

}
  1. garble it:
    garble build -ldflags="-s -w" .

What did you expect to see?

It should print what I choose.

What did you see instead?

panic:

panic: template: prompt:4:19: executing "option" at <.CurrentOpt.Value>: can't evaluate field Value in type hXCS2oWxzi9.DYdqhhUhlOQ

goroutine 1 [running]:
main.uHhC2SXRwzv()
        Oeubp4hOAGzv.go:1 +0x1b1
main.main()
        FQt7OAGNPv.go:1 +0x17
@lu4p lu4p added the bug Something isn't working label Dec 6, 2023
@Xiol
Copy link

Xiol commented Jan 2, 2024

I have also come across this, although my error is slightly different:

Error: prompt failure: template: prompt:2:7: executing "prompt" at <.ShowHelp>: can't evaluate field ShowHelp in type GJB2N4R4a5.OalHLhT4uq

My survey.Question's are setup like this:

	hostname, _ = os.Hostname()

	endpointNamePrompt = &survey.Question{
		Name: "endpoint_name",
		Prompt: &survey.Input{
			Message: "Please enter a display name for this endpoint:",
			Default: hostname,
			Help:    fmt.Sprintf("Use the system hostname if you don't have a specific name (hostname: '%s')", hostname),
		},
		Validate: survey.Required,
	}

	endpointIdPrompt = &survey.Question{
		Name: "endpoint_id",
		Prompt: &survey.Input{
			Message: "Please specify an endpoint ID:",
			Default: hostname,
			Help:    fmt.Sprintf("Use the system hostname if you don't have a specific ID (hostname: '%s')", hostname),
		},
		Validate: validateID,
	}

It doesn't always replicate though, which is annoying but probably down to the nature of garble.

FWIW, I never came across this problem with Go 1.20 + garble v0.10.1 - for me it only started occurring after bumping to Go 1.21+garble v0.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reflection
Development

No branches or pull requests

3 participants