Standard library / go/build
go/build.MultiplePackageError.Error()
Returns human-readable package-discovery diagnostic text. Avoid depending on the exact message. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (e *MultiplePackageError) Error() stringReturn Value
string
Returns human-readable package-discovery diagnostic text.
Working Example
Example Snippetgo
package main
import ( "errors" "fmt" "go/build" "os" "path/filepath" "strings")
func check(e error) { if e != nil { panic(e) }}
func main() { d, e := os.MkdirTemp("", "build-error-") check(e) defer os.RemoveAll(d) check(os.WriteFile(filepath.Join(d, "a.go"), []byte("package a"), 0600)) check(os.WriteFile(filepath.Join(d, "b.go"), []byte("package b"), 0600)) _, e = build.ImportDir(d, 0) var x *build.MultiplePackageError ok := errors.As(e, &x) fmt.Println(ok && strings.Contains(x.Error(), d))}