Skip to content

Better Error Message for Compiling Packages with CGO #215

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

Closed
jhleath opened this issue Apr 24, 2015 · 5 comments
Closed

Better Error Message for Compiling Packages with CGO #215

jhleath opened this issue Apr 24, 2015 · 5 comments

Comments

@jhleath
Copy link

jhleath commented Apr 24, 2015

So, now that I have GopherJS setup and working again, I attempted to compile my program. I get the following panic log:

panic: newVariable: empty name [recovered]
    panic: newVariable: empty name

goroutine 1 [running]:
golang.org/x/tools/go/types.(*Checker).handleBailout(0xc2080a4340, 0xc20a03e350)
    /Users/hunter/Documents/Developer/golang/src/golang.org/x/tools/go/types/check.go:218 +0xfc
github.com/gopherjs/gopherjs/compiler.(*funcContext).newVariableWithLevel(0xc20987ec60, 0x0, 0x0, 0xc20a03b901, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/compiler/utils.go:209 +0x9e
github.com/gopherjs/gopherjs/compiler.Compile(0xc20aea6f21, 0x19, 0xc20a896b00, 0x9, 0x10, 0xc208bed740, 0xc208029330, 0x0, 0x885328, 0x0, ...)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/compiler/package.go:168 +0x1575
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc20801efe0, 0xc20a801db0, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:447 +0xf50
github.com/gopherjs/gopherjs/build.(*Session).ImportPackage(0xc20801efe0, 0xc20aea6f21, 0x19, 0xb, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:356 +0x5ea
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc20801efe0, 0xc20a800140, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:399 +0x208a
github.com/gopherjs/gopherjs/build.(*Session).ImportPackage(0xc20801efe0, 0xc209b66681, 0x1b, 0xb, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:356 +0x5ea
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc20801efe0, 0xc20bc6b360, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:399 +0x208a
github.com/gopherjs/gopherjs/build.(*Session).ImportPackage(0xc20801efe0, 0xc20a967dc1, 0x1e, 0x6, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:356 +0x5ea
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc20801efe0, 0xc20b08c960, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:399 +0x208a
github.com/gopherjs/gopherjs/build.(*Session).ImportPackage(0xc20801efe0, 0xc20801f101, 0x12, 0x0, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:356 +0x5ea
github.com/gopherjs/gopherjs/build.*Session.ImportPackage·fm(0xc20801f101, 0x12, 0x1d27a5, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:260 +0x4d
github.com/gopherjs/gopherjs/compiler.func·012(0xc20806f4a0, 0xc20801f101, 0x12, 0x12, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/compiler/package.go:85 +0x63
golang.org/x/tools/go/types.(*Checker).collectObjects(0xc2080a4340)
    /Users/hunter/Documents/Developer/golang/src/golang.org/x/tools/go/types/resolver.go:182 +0x29e4
golang.org/x/tools/go/types.(*Checker).Files(0xc2080a4340, 0xc20802c1c8, 0x1, 0x1, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/golang.org/x/tools/go/types/check.go:228 +0xba
golang.org/x/tools/go/types.(*Config).Check(0xc208098d80, 0x589770, 0x4, 0xc208098040, 0xc20802c1c8, 0x1, 0x1, 0xc2080aa050, 0x16d94, 0x0, ...)
    /Users/hunter/Documents/Developer/golang/src/golang.org/x/tools/go/types/api.go:340 +0xbb
github.com/gopherjs/gopherjs/compiler.Compile(0x589770, 0x4, 0xc20802c1c8, 0x1, 0x1, 0xc208098040, 0xc208029330, 0x419c00, 0xc2080291fc, 0x0, ...)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/compiler/package.go:102 +0x581
github.com/gopherjs/gopherjs/build.(*Session).BuildPackage(0xc20801efe0, 0xc20802f810, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:447 +0xf50
github.com/gopherjs/gopherjs/build.(*Session).BuildFiles(0xc20801efe0, 0xc208029310, 0x1, 0x1, 0xc208029295, 0x9, 0xc20802f7c0, 0x42, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/build/build.go:323 +0x3d7
main.func·001(0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/tool.go:101 +0xc05
main.handleError(0xc20a03fc10, 0xc20802bfc0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/tool.go:565 +0x2f
main.func·002(0xc208096000, 0xc208029310, 0x1, 0x1)
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/tool.go:128 +0x14d
github.com/spf13/cobra.(*Command).execute(0xc208096000, 0xc2080292d0, 0x1, 0x1, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/spf13/cobra/command.go:442 +0x410
github.com/spf13/cobra.(*Command).Execute(0xc2080969a0, 0x0, 0x0)
    /Users/hunter/Documents/Developer/golang/src/github.com/spf13/cobra/command.go:507 +0x51b
main.main()
    /Users/hunter/Documents/Developer/golang/src/github.com/gopherjs/gopherjs/tool.go:448 +0x1681

I am not quite sure what is happening. The program is fairly complicated (and uses the "net" package, which I know is not supported), so I'm not sure if that could be causing it. Thanks for letting me know!

go version go1.4 darwin/amd64

Darwin Hunters-MacBook-Pro.local 14.1.0 Darwin Kernel Version 14.1.0: Mon Dec 22 23:10:38 PST 2014; root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64
@jhleath
Copy link
Author

jhleath commented Apr 24, 2015

Okay, so apparently that error only occurs on the first run of gopherjs build. On the subsequent runs, I get the following error.

import error /Users/hunter/Documents/Developer/golang/pkg/darwin_js/github.com/mattn/go-sqlite3.a:2:1 (byte offset = 9): expected Ident, got "\n" ()

@dmitshur
Copy link
Member

If you're trying to compile github.com/mattn/go-sqlite3 package with GopherJS, it won't work because that package uses cgo (it imports the "C" pseudo-package), which is not supported.

That said, perhaps there should be a more graceful error message.

@jhleath
Copy link
Author

jhleath commented Apr 24, 2015

Thanks for the quick response. I thought I remembered reading something ages ago about GopherJS and the go-sqlite3 package because of cgo. I thought that had something to do with it, but I thought that a panic error was probably not the intention. I'll leave this open with the hopes of someone changing the error, but feel free to close it if you decide it isn't worth adding.

@jhleath jhleath changed the title panic: newVariable: empty name [recovered] Better Error Message for Compiling Packages with CGO Apr 24, 2015
@neelance
Copy link
Member

There should be a proper error message when importing "C", but I'll check, maybe there's a regression or some other bug.

@huntaub I'm curious about what you are trying to do. Will your code run in the browser?

@jhleath
Copy link
Author

jhleath commented Apr 24, 2015

Well, if by, "will it run in the browser", you are asking whether I was compiling this with the expectation of it just working, then answer is no (because it does use the sqlite and net packages). I was just ensuring that GopherJS was working on my system (which is probably a poor way to test it).

I can tell you that it appears that the error (panic and import) occur when the gopherjs tool begins to compile the sqlite3 message.

nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Mar 19, 2022
GopherJS doesn't support CGo. This was originally enabled to address
gopherjs#215 by providing a better
error when attempting to build a CGo package (instead of a compiler
panic). However, this approach makes GopherJS refuse to build packages,
which have a CGo and purego versions guarded by the `cgo` build tag:
GopherJS woudl try to load the cgo version and error out.

After this change GopherJS won't attempt to load Go sources with `import
"C"`, and it will load sources with `//go:build !cgo` instead. For
packages that require CGo one of the following errors will be returned:

  - "No buildable sources" if all Go sources import C.
  - "Undefined symbol" for symbols defined in the Go sources that import
    C and that are referenced by other Go source files.
  - "Unknown import path C" if you try to `gopherjs run` a source with
    import C directly.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Mar 19, 2022
GopherJS doesn't support CGo. This was originally enabled to address
gopherjs#215 by providing a better
error when attempting to build a CGo package (instead of a compiler
panic). However, this approach makes GopherJS refuse to build packages,
which have a CGo and purego versions guarded by the `cgo` build tag:
GopherJS woudl try to load the cgo version and error out.

After this change GopherJS won't attempt to load Go sources with `import
"C"`, and it will load sources with `//go:build !cgo` instead. For
packages that require CGo one of the following errors will be returned:

  - "No buildable sources" if all Go sources import C.
  - "Undefined symbol" for symbols defined in the Go sources that import
    C and that are referenced by other Go source files.
  - "Unknown import path C" if you try to `gopherjs run` a source with
    import C directly.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Mar 20, 2022
GopherJS doesn't support CGo. This was originally enabled to address
gopherjs#215 by providing a better
error when attempting to build a CGo package (instead of a compiler
panic). However, this approach makes GopherJS refuse to build packages,
which have a CGo and purego versions guarded by the `cgo` build tag:
GopherJS woudl try to load the cgo version and error out.

After this change GopherJS won't attempt to load Go sources with `import
"C"`, and it will load sources with `//go:build !cgo` instead. For
packages that require CGo one of the following errors will be returned:

  - "No buildable sources" if all Go sources import C.
  - "Undefined symbol" for symbols defined in the Go sources that import
    C and that are referenced by other Go source files.
  - "Unknown import path C" if you try to `gopherjs run` a source with
    import C directly.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Apr 10, 2022
GopherJS doesn't support CGo. This was originally enabled to address
gopherjs#215 by providing a better
error when attempting to build a CGo package (instead of a compiler
panic). However, this approach makes GopherJS refuse to build packages,
which have a CGo and purego versions guarded by the `cgo` build tag:
GopherJS woudl try to load the cgo version and error out.

After this change GopherJS won't attempt to load Go sources with `import
"C"`, and it will load sources with `//go:build !cgo` instead. For
packages that require CGo one of the following errors will be returned:

  - "No buildable sources" if all Go sources import C.
  - "Undefined symbol" for symbols defined in the Go sources that import
    C and that are referenced by other Go source files.
  - "Unknown import path C" if you try to `gopherjs run` a source with
    import C directly.
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Apr 19, 2022
GopherJS doesn't support CGo. This was originally enabled to address
gopherjs#215 by providing a better
error when attempting to build a CGo package (instead of a compiler
panic). However, this approach makes GopherJS refuse to build packages,
which have a CGo and purego versions guarded by the `cgo` build tag:
GopherJS woudl try to load the cgo version and error out.

After this change GopherJS won't attempt to load Go sources with `import
"C"`, and it will load sources with `//go:build !cgo` instead. For
packages that require CGo one of the following errors will be returned:

  - "No buildable sources" if all Go sources import C.
  - "Undefined symbol" for symbols defined in the Go sources that import
    C and that are referenced by other Go source files.
  - "Unknown import path C" if you try to `gopherjs run` a source with
    import C directly.
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

No branches or pull requests

3 participants