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()
|
||||
scanner := bufio.NewScanner(reader)
|
||||
scanner.Split(splitDockerProgress)
|
||||
lastLine := ""
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if line != "" && ctx.Err() == nil && len(events) < cap(events)-1 {
|
||||
events <- pullEvent{line: line}
|
||||
if line != "" {
|
||||
lastLine = line
|
||||
if ctx.Err() == nil && len(events) < cap(events)-1 {
|
||||
events <- pullEvent{line: line}
|
||||
}
|
||||
}
|
||||
}
|
||||
err := cmd.Wait()
|
||||
if err == nil {
|
||||
err = scanner.Err()
|
||||
} else {
|
||||
err = pullCommandError(err, lastLine)
|
||||
}
|
||||
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 {
|
||||
return func() tea.Msg {
|
||||
event, ok := <-events
|
||||
@@ -779,8 +792,8 @@ func (m prsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
if row.kind == "remote" {
|
||||
if row.imageState != "yes" {
|
||||
m.status = fmt.Sprintf("PR #%d cannot start: image is %s", row.pr.Number, row.imageState)
|
||||
if row.imageState == "checking" {
|
||||
m.status = fmt.Sprintf("PR #%d image check is still in progress", row.pr.Number)
|
||||
return m, nil
|
||||
}
|
||||
return m, m.beginPull(*row)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -83,9 +84,9 @@ func TestRemotePRBuildUsesTemporaryPRWorkflow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRWithoutImageDoesNotLaunch(t *testing.T) {
|
||||
func TestPRImageCheckInProgressDoesNotLaunch(t *testing.T) {
|
||||
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))
|
||||
|
||||
updated, cmd := m.Update(tea.KeyPressMsg(tea.Key{Code: tea.KeyEnter}))
|
||||
@@ -93,11 +94,18 @@ func TestPRWithoutImageDoesNotLaunch(t *testing.T) {
|
||||
if cmd != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
m := newPRsModel()
|
||||
m.rows = []prRow{{
|
||||
|
||||
Reference in new issue
Block a user