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

x/text/cmd/gotext: extract command crash if no messages #26312

Open
Chocanto opened this issue Jul 10, 2018 · 11 comments
Open

x/text/cmd/gotext: extract command crash if no messages #26312

Chocanto opened this issue Jul 10, 2018 · 11 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Chocanto
Copy link

Chocanto commented Jul 10, 2018

What version of Go are you using (go version)?

go1.9.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

windows/amd64

What did you do?

Run gotext extract command on a project directory without any messages to extract and no golang.org/x/text/message import.

What did you expect to see?

A blank or error response.

What did you see instead?

A runtime error :

>gotext extract
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x866423]

goroutine 1 [running]:
golang.org/x/text/message/pipeline.(*extracter).seedEndpoints(0xc0421c6000)
        C:/GO-projects/src/golang.org/x/text/message/pipeline/extract.go:100 +0x63
golang.org/x/text/message/pipeline.Extract(0xc0420dc750, 0x1, 0x1, 0x0)
        C:/GO-projects/src/golang.org/x/text/message/pipeline/extract.go:45 +0x5c
main.runExtract(0xd6c4c0, 0xc0420dc750, 0xc042046390, 0x0, 0x0, 0x0, 0x0)
        C:/GO-projects/src/golang.org/x/text/cmd/gotext/extract.go:29 +0x63
main.main()
        C:/GO-projects/src/golang.org/x/text/cmd/gotext/main.go:150 +0x34e
@gopherbot gopherbot added this to the Unreleased milestone Jul 10, 2018
@meirf
Copy link
Contributor

meirf commented Jul 16, 2018

Looks like this started with golang/text@2cb4393 "message/pipeline: use ssa and callgraph":

Specifically on this line where there is no check whether Program.Package's returned PackageInfo is nil.

@mpvl, I guess the question is: should the output be an error or blank?

@mvrhov
Copy link

mvrhov commented Jul 21, 2018

I've also hit this as I'm testing the library. IMO the executable should say that there is no translation strings to extract.
However I'd say that the extract command doesn't work per se.

func (me *LoginFormData) Validate(r *http.Request) error {
	T := context.GetDataFromContext(r.Context()).Trans

	 _= T.Sprint("The email address you entered is not valid")) //TRANS:

	return nil
}

Will also fail with above error.. And I think this will be a common usecase

@olivere
Copy link

olivere commented Sep 6, 2018

FWIW I've started to dig deeper into this issue and this is what I found.

I get this error when using vendored dependencies with e.g. dep. The reasons seems to be that the x.iprog.Package("golang.org/x/text/message") in ...

pkg := x.prog.Package(x.iprog.Package("golang.org/x/text/message").Pkg)

... is nil because the x.iprog *ssa.Program will only find the vendored dependency (e.g. github.com/myorg/myproject/vendor/golang.org/x/text/message) but not golang.org/x/text/message.

@msama
Copy link

msama commented Nov 21, 2018

We are having the same issue with vendored dependencies:

gotext: extract failed: pipeline: golang.org/x/text/message is not imported

Is it there a workaround?

@fgm
Copy link

fgm commented Dec 13, 2018

@msama In a similar case, adding import _ "golang.org/x/text/message" at the top-level import fixed the issue for me

@adlecluse
Copy link

Having the same issue when using a vendor folder. When the vendor folder is removed, it works. I just revendor afterwards for the moment.

@dragon9783
Copy link

@fgm Hello, how to add import _ "golang.org/x/text/message at the top-level import? Can you share some code snippet?

@fgm
Copy link

fgm commented Feb 21, 2019

@dragon9783 this little line is the code snippet: just add it at the top-level package of your library/command (the main package if it's a command)/

@roman-popenov-zz
Copy link

I still have the same issue, and import _ "golang.org/x/text/message at the top-level import doesn't seem to solve it.

@roman-popenov-zz
Copy link

I have solved the issue by running rm -rf vendor/golang.org/x/text command from the root of the project. Of course for things to work, I also needed to have gotext installed. This can be done by running go get golang.org/x/text/cmd/gotext.

@roman-popenov-zz
Copy link

I believe the issue could be solved if binaries of text/message are installed in the GOPATH/bin as well

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 12, 2020
@seankhliao seankhliao changed the title x/text: "gotext extract" command crash if no messages x/text/cmd/gotext: extract command crash if no messages Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests