Keep Go's indented continuation in a step's cause: the composer's reason ended at "requires" and hid the module that could not be found (issue 1966)
mesh/check being carried to da2aa9183221 on fd4931a75261 | from 8acad77d33f9
mesh/delivery merged: source.main moved to novox/mesh-catalog@fd4931a75261
mesh/check being carried to da2aa9183221 on fd4931a75261 | from 8acad77d33f9
mesh/delivery merged: source.main moved to novox/mesh-catalog@fd4931a75261
Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -97,9 +97,10 @@ func (m *Module) candidate(ctx context.Context, workspace string) (string, error
|
||||
// compileError is the first line of the compiler's output that says an error: not the `# package` heading go build
|
||||
// prints above a package's errors, nor Go's progress.
|
||||
func compileError(out string) string {
|
||||
for _, l := range strings.Split(out, "\n") {
|
||||
lines := strings.Split(out, "\n")
|
||||
for i, l := range lines {
|
||||
if l = strings.TrimSpace(l); l != "" && !strings.HasPrefix(l, "#") && !strings.HasPrefix(l, "go: downloading ") {
|
||||
return l
|
||||
return withContinuation(l, lines[i+1:])
|
||||
}
|
||||
}
|
||||
return firstLine(out)
|
||||
|
||||
@@ -351,15 +351,33 @@ func (m *Module) now() time.Time { return m.clock() }
|
||||
// causeLine is the first line of a go command's output that says something other than Go's own progress: `go:
|
||||
// downloading ...` comes first when Go fetches a module, and `# <package>` heads a compile error of go build or go vet
|
||||
// (issue 1703: the reason said only the package), and the cause of a failure on a later line.
|
||||
//
|
||||
// A cause Go writes over several lines keeps its indented continuation lines, joined by a space: a module graph error
|
||||
// is "X requires" with the module that fails, and why, on the next line (issue 1966: the composer's reason ended at
|
||||
// "requires" and hid "golang.org/x/tools@v0.42.0: module lookup disabled").
|
||||
func causeLine(s string) string {
|
||||
for _, l := range strings.Split(s, "\n") {
|
||||
lines := strings.Split(s, "\n")
|
||||
for i, l := range lines {
|
||||
if l = strings.TrimSpace(l); l != "" && !strings.HasPrefix(l, "go: downloading ") && !strings.HasPrefix(l, "# ") {
|
||||
return l
|
||||
return withContinuation(l, lines[i+1:])
|
||||
}
|
||||
}
|
||||
return firstLine(s)
|
||||
}
|
||||
|
||||
// withContinuation is first with each following line Go indented under it, trimmed and joined by a space.
|
||||
func withContinuation(first string, rest []string) string {
|
||||
for _, l := range rest {
|
||||
if !strings.HasPrefix(l, "\t") && !strings.HasPrefix(l, " ") {
|
||||
break
|
||||
}
|
||||
if l = strings.TrimSpace(l); l != "" {
|
||||
first += " " + l
|
||||
}
|
||||
}
|
||||
return first
|
||||
}
|
||||
|
||||
func firstLine(s string) string {
|
||||
for _, l := range strings.Split(s, "\n") {
|
||||
if l = strings.TrimSpace(l); l != "" {
|
||||
|
||||
@@ -309,9 +309,14 @@ func TestCauseLineSkipsProgressAndThePackageHeading(t *testing.T) {
|
||||
"go: downloading x v1\n# git.example/m/cmd\n./main.go:3:2: undefined: y\n": "./main.go:3:2: undefined: y",
|
||||
"\ngo: example.com/x@v1: reading: 404\n": "go: example.com/x@v1: reading: 404",
|
||||
"go: downloading x v1\n": "go: downloading x v1",
|
||||
// issue 1966: a module graph error goes on, indented, on the next line; a later error is not taken in.
|
||||
"a.go:3:8: x@v1 requires\n\ty@v2: module lookup disabled by GOPROXY=off\nb.go:1:1: other\n": "a.go:3:8: x@v1 requires y@v2: module lookup disabled by GOPROXY=off",
|
||||
} {
|
||||
if got := causeLine(in); got != want {
|
||||
t.Errorf("causeLine(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
if got := compileError(in); got != want {
|
||||
t.Errorf("compileError(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user