Open noerw opened 2 years ago
Note the invocation won't succeed even if the panic is fixed, ''
passes an argument of an empty string and go
requires flags to come before other arguments.
More minimal panic:
$ go build '="'
panic: path "=\"" not in error "invalid import path \"=\\\"\"" [recovered]
panic: path "=\"" not in error "invalid import path \"=\\\"\""
cc @bcmills @matloob
Hello, I am trying to fix this.
Once double quoted string appears in the import path, build panics. for example: go build '"a"'
also crash:
$ go version
go version go1.17 darwin/amd64
In "cmd/go/internal/load/pkg.go", ImportErrorf
checks whether the path
(importError.importPath
) is contained in err
(importError.err
):
// func ImportErrorf
if errStr := err.Error(); !strings.Contains(errStr, path) {
panic(fmt.Sprintf("path %q not in error %q", path, errStr))
}
err
is created by stmt like fmt.Errorf("invalid import path %q", importPath)
, so the import path in error message is escaped. If import path contians any char that can be escaped by %q
, strings.Contains
returns false.
IMO, this check is quite unreasonable, do we really need it?
Change https://golang.org/cl/358815 mentions this issue: cmd/go: make escape consistent in ImportErrorf
Change https://golang.org/cl/372398 mentions this issue: cmd/go/internal/load: prevent calling ImportErrorf when the err is *module.InvalidPathError
@bcmills , Is the above CL(https://golang.org/cl/372398) working well for the Issue or else is still there is someother changes required for this.
Change https://go.dev/cl/452715 mentions this issue: cmd/go/internal/load: bypass calling ImportErrorf function
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes (1.17.2)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
run either of these commands in any go project dir
What did you expect to see?
The compilation should succeed, as it does when removing the
''
.What did you see instead?