You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
metrics = err: go command required, not found: exec: "go": executable file not found in $PATH: stderr:
When executed in an environment where an executable go is unavailable, such as inside a browser via WebAssembly (GOOS=js GOARCH=wasm), or inside the Go Playground.
It's possible to provide a custom PackagePathToName function via an option, such as:
fmt.Println("metrics =", valast.StringWithOptions(face.Metrics(), &valast.Options{
PackagePathToName: func(pathstring) (string, error) { returnpathpkg.Base(path), nil }, // TODO: Handle paths like example.com/foo/v2, where the name is 'foo' not 'v2'.
}))
Then it doesn't get the aforementioned error.
Is this intended behavior for String, or should valast know that GOOS=js GOARCH=wasm environment cannot execute a go binary and should automatically use a different PackagePathToName implementation, so that it's possible to use String?
Note that both spew.Dump(face.Metrics()) and goon.Dump(face.Metrics()) print an output without an error inside a browser.
The text was updated successfully, but these errors were encountered:
From what I can tell, this particular dependence on the go binary comes from DefaultPackagePathToName, which uses golang.org/x/tools/go/packages. When the packages.Load call with its current &packages.Config{Mode: packages.NeedName} config selects the goListDriver driver, that driver uses go list to load information about packages.
dmitshur
changed the title
String method is not viable in environments where executable go is unavailable
String function is not viable in environments where executable go is unavailable
Sep 21, 2021
Ahhh, that makes more sense. For context, through reflection we are able to get a types’ package import path - but we aren’t sure how we should refer to it canonically in code (import path != name, as you know) so that is what DefaultPackagePathToName is doing.
I wonder what go-spew and go-goon do in this case? I guess your original comment about using a different default implementation under ‘ GOOS=js GOARCH=wasm’ may be the right path forward!
Consider the following (minified) example program that tries to print a value of type
font.Metrics
:(https://play.golang.org/p/6nQBdwaHo5q)
It prints:
When executed in an environment where an executable
go
is unavailable, such as inside a browser via WebAssembly (GOOS=js GOARCH=wasm
), or inside the Go Playground.It's possible to provide a custom
PackagePathToName
function via an option, such as:Then it doesn't get the aforementioned error.
Is this intended behavior for
String
, or shouldvalast
know thatGOOS=js GOARCH=wasm
environment cannot execute ago
binary and should automatically use a differentPackagePathToName
implementation, so that it's possible to useString
?Note that both
spew.Dump(face.Metrics())
andgoon.Dump(face.Metrics())
print an output without an error inside a browser.The text was updated successfully, but these errors were encountered: