diff --git a/cmd/backport-batch/README.md b/cmd/backport-batch/README.md index 81afd0ef6..4919035c0 100644 --- a/cmd/backport-batch/README.md +++ b/cmd/backport-batch/README.md @@ -27,6 +27,8 @@ Requires `git` and an authenticated `gh` on PATH, and a remote called `origin`. Build the binary wherever an exit code matters: `go run` turns any non-zero exit into its own `1`, so under it a check that could not be completed looks the same as one that found something missing. +A command whose output on stdout could not be written exits 2 where it would have exited 0, and says on stderr that the output was lost; anything the run did before that, a push or a published pull request included, has still happened. + ### run Switches the current working tree to `backport-batch/-`, created at `origin/`, and picks onto it one original at a time, in the order they merged into `main`, as one unit each on the branch's first-parent line. A pull request merged into `main` with a merge commit `M` goes on as its own commits, `git rev-list --reverse --topo-order --no-merges M^1..M^2`, each picked with `git cherry-pick -x --signoff`, so each keeps its author, message and sign-offs and gains the `(cherry picked from commit …)` line; the merges that brought `main` into its branch are left out, since `main` already has what they brought. A merge commit then joins the picks to the batch: its first parent is the batch before the original, its second the last pick, and its message is `M`'s with a paragraph of its own, `Backported-from: M`. A pull request squash-merged into `main` goes on as one pick. When any commit of an original conflicts, the pick is aborted, the branch goes back to where it was before that original, and the original is recorded with the commit that failed and its files; the run goes on with the next one. A commit the branch already carries is skipped as empty, and an original none of whose commits changes anything is reported as carried. The tree has to be clean. A local branch of that name is reset to where the run starts; when that drops commits only it has, the run first prints its tip and the `git branch` command that restores them, and so does `--defer`. Signing follows your git configuration; hooks are off for the picks and the merge, so each commit carries its message as git writes it. diff --git a/cmd/backport-batch/assemble.go b/cmd/backport-batch/assemble.go index 3c025517e..a0aab98db 100644 --- a/cmd/backport-batch/assemble.go +++ b/cmd/backport-batch/assemble.go @@ -153,7 +153,7 @@ func (a *app) run(args []string) int { } // The scheduled job has half an hour for every line; this says where it // goes. - fmt.Fprintf(a.stderr, "prepared %s in %s, %s of it judging partial units and what originals build on\n", l.branch(), time.Since(started).Round(time.Millisecond), b.detecting.Round(time.Millisecond)) + _, _ = fmt.Fprintf(a.stderr, "prepared %s in %s, %s of it judging partial units and what originals build on\n", l.branch(), time.Since(started).Round(time.Millisecond), b.detecting.Round(time.Millisecond)) if drops != nil { return a.redrop(b, drops, reason, *undropArg != "", *push) } @@ -449,20 +449,20 @@ func (a *app) finish(b *batch, r *report, branch string, date time.Time, push, r } body, left := r.body(template) p.body = body - fmt.Fprint(a.stdout, body) + _, _ = fmt.Fprint(a.stdout, body) skipped := 0 for _, items := range r.skipped { skipped += len(items) } for _, rule := range left { for _, v := range r.skipped[rule] { - fmt.Fprintf(a.stderr, "skipped by %s: %s %s (%s)\n", ruleName(rule), v.o.url(), terminalSafe(v.o.title), terminalSafe(v.reason)) + _, _ = fmt.Fprintf(a.stderr, "skipped by %s: %s %s (%s)\n", ruleName(rule), v.o.url(), terminalSafe(v.o.title), terminalSafe(v.reason)) } } for _, p := range r.waiting { - fmt.Fprintf(a.stderr, "waiting for a maintainer: %s %s changes %s\n", p.v.o.url(), terminalSafe(p.v.o.title), terminalSafe(strings.Join(p.files, ", "))) + _, _ = fmt.Fprintf(a.stderr, "waiting for a maintainer: %s %s changes %s\n", p.v.o.url(), terminalSafe(p.v.o.title), terminalSafe(strings.Join(p.files, ", "))) } - fmt.Fprintf(a.stderr, "%s at %.12s: %d on the branch, %d deferred, %d waiting for a maintainer, %d skipped\ntitle: %s\nreport: %s\n", + _, _ = fmt.Fprintf(a.stderr, "%s at %.12s: %d on the branch, %d deferred, %d waiting for a maintainer, %d skipped\ntitle: %s\nreport: %s\n", branch, head, len(r.onBranch), len(r.deferred)+len(r.held), len(r.waiting), skipped, p.title, doc.ID) if !push { return 0 @@ -471,8 +471,8 @@ func (a *app) finish(b *batch, r *report, branch string, date time.Time, push, r // Picking nothing is not a failure of the run; check still reports // whatever the line lacks. Merged and closed batches are never // written, so there is nowhere to keep what the run found. - fmt.Fprintf(a.stderr, "%s carries nothing beyond %s; nothing to push\n", branch, b.line.branch()) - fmt.Fprintf(a.stderr, "no batch pull request is open on %s; this run's classification is not retained\n", b.line.branch()) + _, _ = fmt.Fprintf(a.stderr, "%s carries nothing beyond %s; nothing to push\n", branch, b.line.branch()) + _, _ = fmt.Fprintf(a.stderr, "no batch pull request is open on %s; this run's classification is not retained\n", b.line.branch()) return 0 } if err := a.publish(b, p, rebuilt); err != nil { @@ -537,7 +537,7 @@ func (a *app) warnReset(branch, start string) error { if err != nil || kept { return err } - fmt.Fprintf(a.stderr, "resetting the local %s from %s, dropping commits %.12s does not carry; git branch %s-%.12s %s restores them\n", branch, old, start, branch, old, old) + _, _ = fmt.Fprintf(a.stderr, "resetting the local %s from %s, dropping commits %.12s does not carry; git branch %s-%.12s %s restores them\n", branch, old, start, branch, old, old) return nil } @@ -733,7 +733,7 @@ func (a *app) publish(b *batch, p publication, rebuilt bool) error { if err != nil { return err } - fmt.Fprintf(a.stderr, "opened draft %s\n", url) + _, _ = fmt.Fprintf(a.stderr, "opened draft %s\n", url) if err := a.postReport(n, p.report); err != nil { return fmt.Errorf("posting report %.12s on #%d: %w; the body keeps it, and the next run --push posts it", p.report.doc.ID, n, err) } @@ -745,7 +745,7 @@ func (a *app) publish(b *batch, p publication, rebuilt bool) error { if err := a.gh.editPull(b.pr.Number, p.title, name); err != nil { return err } - fmt.Fprintf(a.stderr, "updated %s\n", pullURL(b.pr)) + _, _ = fmt.Fprintf(a.stderr, "updated %s\n", pullURL(b.pr)) return nil } @@ -861,7 +861,7 @@ func (a *app) finishClose(l line, url string, c closing) error { if err := a.deleteBranch(l, c); err != nil { return err } - fmt.Fprintf(a.stderr, "closed %s: without what is deferred it carries nothing beyond %s; the next batch tries them again\n", url, l.branch()) + _, _ = fmt.Fprintf(a.stderr, "closed %s: without what is deferred it carries nothing beyond %s; the next batch tries them again\n", url, l.branch()) return nil } @@ -933,7 +933,7 @@ func (a *app) resumeClose(b *batch, push, changing bool) (bool, int) { if err := a.deleteBranch(b.line, c); err != nil { return false, a.fail(err) } - fmt.Fprintf(a.stderr, "deleted %s, which the close of #%d left\n", c.Branch, c.PR) + _, _ = fmt.Fprintf(a.stderr, "deleted %s, which the close of #%d left\n", c.Branch, c.PR) return false, a.finished(c, changing) } diff --git a/cmd/backport-batch/check.go b/cmd/backport-batch/check.go index d8acf4e37..2101d251f 100644 --- a/cmd/backport-batch/check.go +++ b/cmd/backport-batch/check.go @@ -73,14 +73,14 @@ func (a *app) check(args []string) int { case d.kind == outcomeWarning: a.warn("%s", d.text) case d.kind == outcomeNote: - fmt.Fprintf(a.stderr, "note: %s\n", d.text) + _, _ = fmt.Fprintf(a.stderr, "note: %s\n", d.text) } } if len(missing)+len(failing) == 0 { if *cut { - fmt.Fprintf(a.stdout, "%s: no change the policy takes is missing before the cut\n", l.branch()) + _, _ = fmt.Fprintf(a.stdout, "%s: no change the policy takes is missing before the cut\n", l.branch()) } else { - fmt.Fprintf(a.stdout, "%s: every change the policy takes is on the line or on the batch\n", l.branch()) + _, _ = fmt.Fprintf(a.stdout, "%s: every change the policy takes is on the line or on the batch\n", l.branch()) } return 0 } @@ -89,13 +89,13 @@ func (a *app) check(args []string) int { where = "nor on batch pull request #" + strconv.Itoa(b.pr.Number) } if len(missing) > 0 { - fmt.Fprintf(a.stdout, "%s: %d changes the policy takes are not on the line, %s:\n", l.branch(), len(missing), where) + _, _ = fmt.Fprintf(a.stdout, "%s: %d changes the policy takes are not on the line, %s:\n", l.branch(), len(missing), where) for _, text := range missing { - fmt.Fprintf(a.stdout, " %s\n", text) + _, _ = fmt.Fprintf(a.stdout, " %s\n", text) } } for _, text := range failing { - fmt.Fprintf(a.stdout, "%s: %s\n", l.branch(), text) + _, _ = fmt.Fprintf(a.stdout, "%s: %s\n", l.branch(), text) } return 1 } @@ -326,10 +326,10 @@ func (a *app) fold(args []string) int { return a.fail(err) } if why != "" { - fmt.Fprintf(a.stdout, "refused: %s\n", why) + _, _ = fmt.Fprintf(a.stdout, "refused: %s\n", why) return 1 } - fmt.Fprintln(a.stdout, "ok") + _, _ = fmt.Fprintln(a.stdout, "ok") return 0 } diff --git a/cmd/backport-batch/main.go b/cmd/backport-batch/main.go index 23b357dff..19102e57f 100644 --- a/cmd/backport-batch/main.go +++ b/cmd/backport-batch/main.go @@ -111,6 +111,9 @@ type app struct { policyRef string // tool is the commit backport-batch was built from, for the record. tool string + // unwritten is the first error writing to stdout, which fails the run: + // what it printed never reached its reader. + unwritten error } func main() { @@ -119,10 +122,21 @@ func main() { } func (a *app) main(args []string) int { - a.stdout, a.stderr = textWriter{a.stdout}, textWriter{a.stderr} + a.stdout, a.stderr = textWriter{w: a.stdout, failed: &a.unwritten}, textWriter{w: a.stderr} + code := a.command(args) + if a.unwritten != nil { + _, _ = fmt.Fprintf(a.stderr, "backport-batch: output was lost: %v; anything the run did, such as a push or a publish, still happened\n", a.unwritten) + if code == 0 { + code = 2 + } + } + return code +} + +func (a *app) command(args []string) int { a.gh = &permCache{github: a.gh, perms: map[string]string{}} if len(args) == 0 { - fmt.Fprint(a.stderr, usageText) + _, _ = fmt.Fprint(a.stderr, usageText) return 2 } if bot := a.gh.batchBot(); bot != "" && !botLoginRE.MatchString(bot) { @@ -144,20 +158,26 @@ func (a *app) main(args []string) int { case "lines": return a.lines(args[1:]) case "-h", "--help", "help": - fmt.Fprint(a.stdout, usageText) + _, _ = fmt.Fprint(a.stdout, usageText) return 0 } - fmt.Fprintf(a.stderr, "unknown command %q\n\n%s", args[0], usageText) + _, _ = fmt.Fprintf(a.stderr, "unknown command %q\n\n%s", args[0], usageText) return 2 } // textWriter keeps output fit for a terminal. Titles, file names and the // messages git relays come from other people, and a control sequence among // them would move the cursor or rewrite what was printed before. -type textWriter struct{ w io.Writer } +type textWriter struct { + w io.Writer + failed *error +} func (t textWriter) Write(p []byte) (int, error) { if _, err := io.WriteString(t.w, clean(string(p), true)); err != nil { + if t.failed != nil && *t.failed == nil { + *t.failed = err + } return 0, err } return len(p), nil @@ -166,7 +186,7 @@ func (t textWriter) Write(p []byte) (int, error) { func (a *app) flags(name string) *flag.FlagSet { fs := flag.NewFlagSet(name, flag.ContinueOnError) fs.SetOutput(a.stderr) - fs.Usage = func() { fmt.Fprint(a.stderr, usageText) } + fs.Usage = func() { _, _ = fmt.Fprint(a.stderr, usageText) } return fs } @@ -189,12 +209,12 @@ func parse(fs *flag.FlagSet, args []string) error { } func (a *app) fail(err error) int { - fmt.Fprintf(a.stderr, "backport-batch: %v\n", err) + _, _ = fmt.Fprintf(a.stderr, "backport-batch: %v\n", err) return 2 } func (a *app) warn(format string, args ...any) { - fmt.Fprintf(a.stderr, "warning: "+format+"\n", args...) + _, _ = fmt.Fprintf(a.stderr, "warning: "+format+"\n", args...) } // verdict is what the policy says about one original for the line. diff --git a/cmd/backport-batch/notify.go b/cmd/backport-batch/notify.go index fe301a2ff..3460e287d 100644 --- a/cmd/backport-batch/notify.go +++ b/cmd/backport-batch/notify.go @@ -135,11 +135,11 @@ func (a *app) notify(args []string) int { stalled := days >= stalledAfter var text []string if stalled { - fmt.Fprintf(a.stdout, "%s: batch pull request #%d has been open since %s, %d days\n", l.branch(), pr.Number, opened.Format(time.DateOnly), days) + _, _ = fmt.Fprintf(a.stdout, "%s: batch pull request #%d has been open since %s, %d days\n", l.branch(), pr.Number, opened.Format(time.DateOnly), days) text = append(text, fmt.Sprintf("This batch has been open since %s, %d days, through at least one scheduled run. Merge it, or close it and the next run starts a new one; until then each run adds what the rules take to it.", opened.Format(time.DateOnly), days)) } if len(partial) > 0 { - fmt.Fprintf(a.stdout, "%s: %d units on #%d carry only part of their originals\n", l.branch(), len(partial), pr.Number) + _, _ = fmt.Fprintf(a.stdout, "%s: %d units on #%d carry only part of their originals\n", l.branch(), len(partial), pr.Number) var b strings.Builder b.WriteString("These are on the batch but carry only part of their originals on this line; take each out with `backport-batch run --defer` before the cut, and port what applies as a pull request of its own:\n") for _, n := range partial { @@ -148,7 +148,7 @@ func (a *app) notify(args []string) int { text = append(text, b.String()) } if len(conflicts) > 0 { - fmt.Fprintf(a.stdout, "%s: %d deferred conflicts on #%d wait for a maintainer\n", l.branch(), count(conflicts), pr.Number) + _, _ = fmt.Fprintf(a.stdout, "%s: %d deferred conflicts on #%d wait for a maintainer\n", l.branch(), count(conflicts), pr.Number) var b strings.Builder fmt.Fprintf(&b, "These conflicts wait for a maintainer, as [resolving a conflict](%sresolve-conflict.md) describes; unresolved, each goes to the next batch, and so does what waits on one:\n", tasksURL) for _, n := range conflicts { @@ -158,9 +158,9 @@ func (a *app) notify(args []string) int { } if len(waiting) > 0 { if count(waiting) == len(waiting) { - fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s and wait for a maintainer\n", l.branch(), len(waiting), pr.Number, workflowsDir) + _, _ = fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s and wait for a maintainer\n", l.branch(), len(waiting), pr.Number, workflowsDir) } else { - fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s or wait on one that does\n", l.branch(), len(waiting), pr.Number, workflowsDir) + _, _ = fmt.Fprintf(a.stdout, "%s: %d originals on #%d change %s or wait on one that does\n", l.branch(), len(waiting), pr.Number, workflowsDir) } var b strings.Builder fmt.Fprintf(&b, "These change `%s`, which the batch's token may not push, and wait for a maintainer to bring them over, as [changes to workflows](%s#changes-to-workflows) describes, or wait on one that does:\n", workflowsDir, policyURL) @@ -170,7 +170,7 @@ func (a *app) notify(args []string) int { text = append(text, b.String()) } if len(parks) > 0 { - fmt.Fprintf(a.stdout, "%s: %d parked originals on #%d, named once\n", l.branch(), len(parks), pr.Number) + _, _ = fmt.Fprintf(a.stdout, "%s: %d parked originals on #%d, named once\n", l.branch(), len(parks), pr.Number) var b strings.Builder fmt.Fprintf(&b, "These cannot land on this line whole, so the batch parked them; each is named here once. A maintainer ports what applies as a pull request of its own, as [fixes that exist only on a release line](%s#fixes-that-exist-only-on-a-release-line) describes, or drops the original with `backport-batch run --drop`:\n", policyURL) for _, p := range parks { @@ -354,7 +354,7 @@ func (a *app) lines(args []string) int { return a.fail(err) } for _, l := range slices.Backward(lines) { - fmt.Fprintln(a.stdout, l.branch()) + _, _ = fmt.Fprintln(a.stdout, l.branch()) } return 0 } diff --git a/cmd/backport-batch/output_test.go b/cmd/backport-batch/output_test.go new file mode 100644 index 000000000..0362f44b7 --- /dev/null +++ b/cmd/backport-batch/output_test.go @@ -0,0 +1,56 @@ +/* +Copyright 2026 The Cozystack Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "errors" + "strings" + "testing" + "time" +) + +type failingWriter struct{} + +func (failingWriter) Write([]byte) (int, error) { return 0, errors.New("broken pipe") } + +// Output that never reached its reader fails the command, and stderr says why. +func TestUnwritableOutputFailsTheCommand(t *testing.T) { + var stderr strings.Builder + a := &app{gh: &fakeGH{}, stdout: failingWriter{}, stderr: &stderr} + if code := a.main([]string{"help"}); code != 2 { + t.Fatalf("help with an unwritable stdout = %d, want 2", code) + } + if !strings.Contains(stderr.String(), "broken pipe") { + t.Errorf("stderr does not name the write failure:\n%s", stderr.String()) + } +} + +// A command that already failed keeps its own exit code when its output is +// lost as well: check still says something is missing. +func TestUnwritableOutputKeepsTheCommandsFailure(t *testing.T) { + f := newFixture(t) + f.lines() + f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"}) + var stderr strings.Builder + a := &app{gh: &fakeGH{remoteHead: f.remoteHead}, stdout: failingWriter{}, stderr: &stderr, now: func() time.Time { return f.now }, tool: f.tool} + if code := a.main([]string{"check", "--line", "release-1.1"}); code != 1 { + t.Fatalf("check with #6 missing and an unwritable stdout = %d, want 1\n%s", code, stderr.String()) + } + if !strings.Contains(stderr.String(), "broken pipe") { + t.Errorf("stderr does not name the write failure:\n%s", stderr.String()) + } +} diff --git a/cmd/backport-batch/report.go b/cmd/backport-batch/report.go index d1ae4a4b5..ee072e332 100644 --- a/cmd/backport-batch/report.go +++ b/cmd/backport-batch/report.go @@ -708,7 +708,7 @@ func (a *app) report(args []string) int { return a.fail(fmt.Errorf("batch pull request #%d keeps no report %.12s", pr.Number, *id)) } if *asJSON { - fmt.Fprintln(a.stdout, s.raw) + _, _ = fmt.Fprintln(a.stdout, s.raw) return 0 } a.printReport(&pr, s, inBody, inComment) @@ -721,29 +721,29 @@ func (a *app) report(args []string) int { func (a *app) printReport(pr *pullRequest, s storedReport, inBody *storedReport, inComment bool) { d, b := s.doc, s.doc.Built safe := terminalSafe - fmt.Fprintf(a.stdout, "report %s for %s, made %s by a %s run", safe(d.ID), safe(d.Line), safe(b.At), safe(b.Options.Mode)) + _, _ = fmt.Fprintf(a.stdout, "report %s for %s, made %s by a %s run", safe(d.ID), safe(d.Line), safe(b.At), safe(b.Options.Mode)) if b.Options.NoWorkflowFiles { - fmt.Fprint(a.stdout, " with --no-workflow-files") + _, _ = fmt.Fprint(a.stdout, " with --no-workflow-files") } - fmt.Fprintln(a.stdout) - fmt.Fprintf(a.stdout, " main %s, line %s, newer line %s, policy %s\n batch %s, tool %s, run %s\n", safe(b.Main), safe(b.Line), safe(or(b.Newer, "none")), safe(b.Policy), safe(b.Batch), safe(or(b.Tool, "unknown")), safe(or(b.Run, "none"))) + _, _ = fmt.Fprintln(a.stdout) + _, _ = fmt.Fprintf(a.stdout, " main %s, line %s, newer line %s, policy %s\n batch %s, tool %s, run %s\n", safe(b.Main), safe(b.Line), safe(or(b.Newer, "none")), safe(b.Policy), safe(b.Batch), safe(or(b.Tool, "unknown")), safe(or(b.Run, "none"))) current := "none" if inBody != nil { current = safe(inBody.doc.ID) } switch { case inBody != nil && inBody.doc.ID == d.ID: - fmt.Fprintf(a.stdout, " #%d's body carries this report\n", pr.Number) + _, _ = fmt.Fprintf(a.stdout, " #%d's body carries this report\n", pr.Number) case pr.Head.SHA == b.Batch: - fmt.Fprintf(a.stdout, " #%d's head is %.12s, the batch this report describes, but its body carries report %.12s\n", pr.Number, safe(b.Batch), current) + _, _ = fmt.Fprintf(a.stdout, " #%d's head is %.12s, the batch this report describes, but its body carries report %.12s\n", pr.Number, safe(b.Batch), current) default: - fmt.Fprintf(a.stdout, " publication unconfirmed: #%d's head is %.12s, not %.12s, and its body carries report %.12s\n", pr.Number, safe(pr.Head.SHA), safe(b.Batch), current) + _, _ = fmt.Fprintf(a.stdout, " publication unconfirmed: #%d's head is %.12s, not %.12s, and its body carries report %.12s\n", pr.Number, safe(pr.Head.SHA), safe(b.Batch), current) } if !inComment { if prState(pr) == "open" { - fmt.Fprintln(a.stdout, " comment not posted; the next backport-batch run --push posts it") + _, _ = fmt.Fprintln(a.stdout, " comment not posted; the next backport-batch run --push posts it") } else { - fmt.Fprintf(a.stdout, " comment not posted; kept in the body only, since nothing is written to a %s pull request\n", prState(pr)) + _, _ = fmt.Fprintf(a.stdout, " comment not posted; kept in the body only, since nothing is written to a %s pull request\n", prState(pr)) } } type line struct { @@ -802,22 +802,22 @@ func (a *app) printReport(pr *pullRequest, s storedReport, inBody *storedReport, } slices.SortFunc(lines, func(x, y line) int { return cmp.Compare(x.n, y.n) }) for _, l := range lines { - fmt.Fprintf(a.stdout, "#%d %s\n", l.n, terminalSafe(l.text)) + _, _ = fmt.Fprintf(a.stdout, "#%d %s\n", l.n, terminalSafe(l.text)) } overlay := func(name string, list []int) { if len(list) > 0 { - fmt.Fprintf(a.stdout, "%s: %s\n", name, strings.Trim(fmt.Sprint(list), "[]")) + _, _ = fmt.Fprintf(a.stdout, "%s: %s\n", name, strings.Trim(fmt.Sprint(list), "[]")) } } overlay("stale, still on the batch", d.Overlays.Stale) overlay("only part of it applies, still on the batch", d.Overlays.Partial) for _, e := range d.Overlays.Dropped { - fmt.Fprintf(a.stdout, "dropped: #%d, merged as %.12s, on #%d: %s\n", e.Original, terminalSafe(e.Merge), e.On, terminalSafe(e.Reason)) + _, _ = fmt.Fprintf(a.stdout, "dropped: #%d, merged as %.12s, on #%d: %s\n", e.Original, terminalSafe(e.Merge), e.On, terminalSafe(e.Reason)) } overlay("changed in the pick", d.Overlays.Changed) for _, n := range slices.Sorted(maps.Keys(d.Diag)) { for _, ln := range d.Diag[n] { - fmt.Fprintf(a.stdout, "#%s: %s\n", terminalSafe(n), terminalSafe(ln)) + _, _ = fmt.Fprintf(a.stdout, "#%s: %s\n", terminalSafe(n), terminalSafe(ln)) } } if len(d.Other) > 0 { @@ -825,7 +825,7 @@ func (a *app) printReport(pr *pullRequest, s storedReport, inBody *storedReport, for i, sha := range d.Other { other[i] = safe(sha) } - fmt.Fprintf(a.stdout, "commits on main that merged no pull request: %s\n", strings.Join(other, ", ")) + _, _ = fmt.Fprintf(a.stdout, "commits on main that merged no pull request: %s\n", strings.Join(other, ", ")) } } diff --git a/cmd/backport-batch/verify.go b/cmd/backport-batch/verify.go index 0691df641..03b0e8955 100644 --- a/cmd/backport-batch/verify.go +++ b/cmd/backport-batch/verify.go @@ -66,7 +66,7 @@ func (a *app) verify(args []string) int { return a.fail(err) } if pr == nil { - fmt.Fprintf(a.stdout, "%s: no batch pull request is open; nothing to verify\n", l.branch()) + _, _ = fmt.Fprintf(a.stdout, "%s: no batch pull request is open; nothing to verify\n", l.branch()) return 0 } if head, err = batchHead(pr); err != nil { @@ -102,7 +102,7 @@ func (a *app) verify(args []string) int { } if why != "" { refused = append(refused, why) - fmt.Fprintf(a.stdout, "refused %.12s: %s\n", u.commit, why) + _, _ = fmt.Fprintf(a.stdout, "refused %.12s: %s\n", u.commit, why) continue } seen[v] = u.commit @@ -110,13 +110,13 @@ func (a *app) verify(args []string) int { if !u.merge() { n = 1 } - fmt.Fprintf(a.stdout, "ok %.12s #%d, %d %s\n", u.commit, v.o.number, n, plural(n, "commit")) + _, _ = fmt.Fprintf(a.stdout, "ok %.12s #%d, %d %s\n", u.commit, v.o.number, n, plural(n, "commit")) } if len(refused) > 0 { - fmt.Fprintf(a.stdout, "%s: %d of %d units at %.12s are not originals in the batch's shape\n", l.branch(), len(refused), len(units), head) + _, _ = fmt.Fprintf(a.stdout, "%s: %d of %d units at %.12s are not originals in the batch's shape\n", l.branch(), len(refused), len(units), head) return 1 } - fmt.Fprintf(a.stdout, "%s: %d %s at %.12s, each one original in the batch's shape\n", l.branch(), len(units), plural(len(units), "unit"), head) + _, _ = fmt.Fprintf(a.stdout, "%s: %d %s at %.12s, each one original in the batch's shape\n", l.branch(), len(units), plural(len(units), "unit"), head) return 0 }