A failed build step keeps the head of its error, not the tail alone (H-A-475)
The Node build module kept only the last half of its bound of a failed
command's stderr, so esbuild's error line was pushed out by its Node
launcher's stack trace ("esbuild for code: status 1" with no cause). The
image build module's reason and journal line kept stderr's tail alone too,
and so did the Node module's toolchain install. Each now keeps the head and
the tail within its bound, with "… <n> bytes left out …" between them. The
Go build module keeps a failure's first line, not its tail, and is left as
it is.
Builds: design 47 H2 H-A-475
This commit is contained in:
@@ -273,8 +273,9 @@ func TestTheLaunchersAreTheSDKsRule(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// issue 1703: a failed command's reason keeps stderr's end and stdout's start, each bounded, so a long stdout (npm's
|
||||
// progress) never pushes npm's error out, and tsc's first error on stdout stays in.
|
||||
// issue 1703: a failed command's reason keeps stderr's head and end and stdout's start, each bounded, so a long stdout
|
||||
// (npm's progress) never pushes npm's error out, and tsc's first error on stdout stays in. H-A-475: esbuild's error line
|
||||
// at the head of stderr stays in before its Node launcher's stack trace, the part left out said by its size.
|
||||
func TestRanFailedKeepsTheError(t *testing.T) {
|
||||
noise := strings.Repeat("npm progress line\n", 200)
|
||||
cases := map[string]struct {
|
||||
@@ -283,9 +284,11 @@ func TestRanFailedKeepsTheError(t *testing.T) {
|
||||
wantNot []string
|
||||
}{
|
||||
"passed": {forgekey.Ran{Stdout: "ok"}, nil, nil},
|
||||
"npm, long stdout": {forgekey.Ran{Status: 1, Stdout: noise, Stderr: "npm ERR! early\n" + noise + "npm ERR! code E404\n"}, []string{"status 1", "npm ERR! code E404"}, []string{"npm ERR! early"}},
|
||||
"tsc on stdout": {forgekey.Ran{Status: 2, Stdout: "src/a.ts(1,7): error TS2322: wrong\n" + noise}, []string{"error TS2322"}, nil},
|
||||
"never ran": {forgekey.Ran{Err: "ENOENT"}, []string{"ENOENT"}, nil},
|
||||
"npm, long stdout": {forgekey.Ran{Status: 1, Stdout: noise, Stderr: "npm ERR! early\n" + noise + "npm ERR! code E404\n"}, []string{"status 1", "npm ERR! early", "bytes left out", "npm ERR! code E404"}, nil},
|
||||
"esbuild, a launcher's stack trace": {forgekey.Ran{Status: 1, Stderr: "✘ [ERROR] Could not resolve \"./missing\"\n" + strings.Repeat(" at Object.<anonymous> (/node_modules/esbuild/lib/main.js:1:1)\n", 40)},
|
||||
[]string{"status 1", `[ERROR] Could not resolve "./missing"`, "bytes left out", "main.js:1:1)"}, nil},
|
||||
"tsc on stdout": {forgekey.Ran{Status: 2, Stdout: "src/a.ts(1,7): error TS2322: wrong\n" + noise}, []string{"error TS2322"}, nil},
|
||||
"never ran": {forgekey.Ran{Err: "ENOENT"}, []string{"ENOENT"}, nil},
|
||||
}
|
||||
for name, c := range cases {
|
||||
got := ranFailed(c.ran)
|
||||
|
||||
@@ -172,13 +172,8 @@ func (t Toolchain) open(dir string) error {
|
||||
return os.Chmod(mark, 0o644)
|
||||
}
|
||||
|
||||
func tail(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s) > 400 {
|
||||
s = s[len(s)-400:]
|
||||
}
|
||||
return s
|
||||
}
|
||||
// tail is what a failed toolchain install wrote on stderr, its head and its tail within 400 bytes (H-A-475).
|
||||
func tail(s string) string { return headAndTail(strings.TrimSpace(s), 400) }
|
||||
|
||||
func (t *Toolchain) homeOrEmpty() string {
|
||||
if t == nil {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/forgekey"
|
||||
)
|
||||
@@ -180,18 +181,17 @@ func (m *Module) runIn(ctx context.Context, root string, write bool, dir string,
|
||||
return run(ctx, extra, "env", append([]string{"-C", dir, name}, args...)...)
|
||||
}
|
||||
|
||||
// ranFailed says why a command did not pass, or "" when it did (issue 1703): its exit status, the end of what it wrote
|
||||
// on stderr (npm's error is its last lines) and the start of what it wrote on stdout (tsc writes its errors there,
|
||||
// first first), each bounded, so a long stdout never pushes stderr's error out of the reason.
|
||||
// ranFailed says why a command did not pass, or "" when it did (issue 1703): its exit status, the head and the tail of
|
||||
// what it wrote on stderr (npm's error is its last lines; esbuild's is its first, before its Node launcher's stack
|
||||
// trace, H-A-475) and the start of what it wrote on stdout (tsc writes its errors there, first first), each bounded, so
|
||||
// a long stdout never pushes stderr's error out of the reason.
|
||||
func ranFailed(r forgekey.Ran) string {
|
||||
if r.Status == 0 && r.Err == "" {
|
||||
return ""
|
||||
}
|
||||
why := fmt.Sprintf("status %d %s", r.Status, r.Err)
|
||||
if e := strings.TrimSpace(r.Stderr); e != "" {
|
||||
if len(e) > failedBytes/2 {
|
||||
e = "... " + e[len(e)-failedBytes/2:]
|
||||
}
|
||||
e = headAndTail(e, failedBytes/2)
|
||||
why += ": stderr: " + e
|
||||
}
|
||||
if o := strings.TrimSpace(r.Stdout); o != "" {
|
||||
@@ -205,3 +205,26 @@ func ranFailed(r forgekey.Ran) string {
|
||||
|
||||
// failedBytes bounds what ranFailed carries of a command's output, stderr and stdout half each.
|
||||
const failedBytes = 1500
|
||||
|
||||
// headAndTail is s when it fits in max bytes, else its first and its last part within max, with "… <n> bytes left
|
||||
// out …" between them (H-A-475): a launcher's stack trace at the end never pushes the tool's own error line at the
|
||||
// start out of what is kept, nor the reverse. Both parts are cut on whole characters.
|
||||
func headAndTail(s string, max int) string {
|
||||
if len(s) <= max {
|
||||
return s
|
||||
}
|
||||
mark := func(n int) string { return fmt.Sprintf(" … %d bytes left out … ", n) }
|
||||
room := max - len(mark(len(s)))
|
||||
if room < 2 {
|
||||
room = 2
|
||||
}
|
||||
head := s[:room/2]
|
||||
for len(head) > 0 && !utf8.RuneStart(s[len(head)]) {
|
||||
head = head[:len(head)-1]
|
||||
}
|
||||
tail := s[len(s)-(room-room/2):]
|
||||
for len(tail) > 0 && !utf8.RuneStart(tail[0]) {
|
||||
tail = tail[1:]
|
||||
}
|
||||
return head + mark(len(s)-len(head)-len(tail)) + tail
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user