Skip to content

Commit ebdccd1

Browse files
committed
fix error messages
1 parent 7631051 commit ebdccd1

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

pkg/cmd/gpucreate/gpucreate.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,11 @@ func (c *createContext) waitForInstances(workspaces []*entity.Workspace) {
882882
for _, ws := range workspaces {
883883
err := c.pollUntilReady(ws.ID)
884884
if err != nil {
885-
c.logf(" %s: Timeout waiting for ready state\n", ws.Name)
885+
if strings.Contains(err.Error(), "timeout waiting") {
886+
c.logf(" %s: Timeout waiting for ready state\n", ws.Name)
887+
} else {
888+
c.logf(" %s: %s\n", ws.Name, c.colorize(err.Error(), c.t.Red))
889+
}
886890
}
887891
}
888892
}
@@ -1225,6 +1229,9 @@ func (c *createContext) pollUntilReady(wsID string) error {
12251229
}
12261230

12271231
if ws.Status == entity.Failure {
1232+
if ws.StatusMessage != "" {
1233+
return breverrors.NewValidationError(fmt.Sprintf("instance %s failed: %s", ws.Name, ws.StatusMessage))
1234+
}
12281235
return breverrors.NewValidationError(fmt.Sprintf("instance %s failed", ws.Name))
12291236
}
12301237

pkg/cmd/gpucreate/gpucreate_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gpucreate
33
import (
44
"strings"
55
"testing"
6+
"time"
67

78
"github.com/brevdev/brev-cli/pkg/cmd/gpusearch"
89
"github.com/brevdev/brev-cli/pkg/entity"
@@ -645,3 +646,22 @@ func TestFormatInstanceSpecs(t *testing.T) {
645646
result := formatInstanceSpecs(specs)
646647
assert.Equal(t, "g5.xlarge (1000GB disk), p4d.24xlarge, g6.xlarge (500GB disk)", result)
647648
}
649+
650+
func TestPollUntilReadyReportsWorkspaceFailureMessage(t *testing.T) {
651+
store := NewMockGPUCreateStore()
652+
store.Workspaces["ws-failed"] = &entity.Workspace{
653+
ID: "ws-failed",
654+
Name: "test",
655+
Status: entity.Failure,
656+
StatusMessage: "unexpected end of JSON input",
657+
}
658+
659+
ctx := &createContext{
660+
store: store,
661+
opts: GPUCreateOptions{Timeout: time.Second},
662+
}
663+
664+
err := ctx.pollUntilReady("ws-failed")
665+
666+
assert.ErrorContains(t, err, "instance test failed: unexpected end of JSON input")
667+
}

0 commit comments

Comments
 (0)