fix(dev): surface registry pull errors
This commit is contained in:
2 files changed
+28
-7
No files matched your search
@@ -154,15 +154,21 @@ func startPull(ctx context.Context, cmd *exec.Cmd, events chan<- pullEvent) tea.
|
|||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
scanner.Split(splitDockerProgress)
|
scanner.Split(splitDockerProgress)
|
||||||
|
lastLine := ""
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := strings.TrimSpace(scanner.Text())
|
line := strings.TrimSpace(scanner.Text())
|
||||||
if line != "" && ctx.Err() == nil && len(events) < cap(events)-1 {
|
if line != "" {
|
||||||
events <- pullEvent{line: line}
|
lastLine = line
|
||||||
|
if ctx.Err() == nil && len(events) < cap(events)-1 {
|
||||||
|
events <- pullEvent{line: line}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := cmd.Wait()
|
err := cmd.Wait()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = scanner.Err()
|
err = scanner.Err()
|
||||||
|
} else {
|
||||||
|
err = pullCommandError(err, lastLine)
|
||||||
}
|
}
|
||||||
events <- pullEvent{done: true, err: err}
|
events <- pullEvent{done: true, err: err}
|
||||||
}()
|
}()
|
||||||
@@ -170,6 +176,13 @@ func startPull(ctx context.Context, cmd *exec.Cmd, events chan<- pullEvent) tea.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pullCommandError(err error, lastLine string) error {
|
||||||
|
if lastLine == "" {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%w: %s", err, lastLine)
|
||||||
|
}
|
||||||
|
|
||||||
func waitPull(events <-chan pullEvent) tea.Cmd {
|
func waitPull(events <-chan pullEvent) tea.Cmd {
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
event, ok := <-events
|
event, ok := <-events
|
||||||
@@ -779,8 +792,8 @@ func (m prsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if row.kind == "remote" {
|
if row.kind == "remote" {
|
||||||
if row.imageState != "yes" {
|
if row.imageState == "checking" {
|
||||||
m.status = fmt.Sprintf("PR #%d cannot start: image is %s", row.pr.Number, row.imageState)
|
m.status = fmt.Sprintf("PR #%d image check is still in progress", row.pr.Number)
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
return m, m.beginPull(*row)
|
return m, m.beginPull(*row)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package tui
|
package tui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -83,9 +84,9 @@ func TestRemotePRBuildUsesTemporaryPRWorkflow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPRWithoutImageDoesNotLaunch(t *testing.T) {
|
func TestPRImageCheckInProgressDoesNotLaunch(t *testing.T) {
|
||||||
m := newPRsModel()
|
m := newPRsModel()
|
||||||
m.rows = []prRow{{kind: "remote", pr: gh.PR{Number: 6441, Title: "No image"}, imageState: "no"}}
|
m.rows = []prRow{{kind: "remote", pr: gh.PR{Number: 6441, Title: "Pending image"}, imageState: "checking"}}
|
||||||
m.table.SetRows(buildTableRows(m.rows))
|
m.table.SetRows(buildTableRows(m.rows))
|
||||||
|
|
||||||
updated, cmd := m.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyEnter}))
|
updated, cmd := m.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyEnter}))
|
||||||
@@ -93,11 +94,18 @@ func TestPRWithoutImageDoesNotLaunch(t *testing.T) {
|
|||||||
if cmd != nil {
|
if cmd != nil {
|
||||||
t.Fatal("unavailable image returned a launch command")
|
t.Fatal("unavailable image returned a launch command")
|
||||||
}
|
}
|
||||||
if !strings.Contains(got.status, "cannot start") {
|
if !strings.Contains(got.status, "still in progress") {
|
||||||
t.Fatalf("status = %q, want launch rejection", got.status)
|
t.Fatalf("status = %q, want launch rejection", got.status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullErrorIncludesLastDockerMessage(t *testing.T) {
|
||||||
|
err := pullCommandError(errors.New("exit status 1"), "manifest unknown")
|
||||||
|
if !strings.Contains(err.Error(), "manifest unknown") {
|
||||||
|
t.Fatalf("pull error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDevTableRendersLocalImageSource(t *testing.T) {
|
func TestDevTableRendersLocalImageSource(t *testing.T) {
|
||||||
m := newPRsModel()
|
m := newPRsModel()
|
||||||
m.rows = []prRow{{
|
m.rows = []prRow{{
|
||||||
|
|||||||
Reference in new issue
Block a user