Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,11 @@ type Container struct {

// AppBuild represents a build for a Cerebrium application
type AppBuild struct {
Id string `json:"id"`
Status string `json:"status"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
Id string `json:"id"`
Status string `json:"status"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
InitError *string `json:"initError,omitempty"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As below

Suggested change
InitError *string `json:"initError,omitempty"`
InitError string `json:"initError,omitempty"`

}

// BaseImagePayload represents the payload for creating a base image
Expand Down
34 changes: 23 additions & 11 deletions internal/ui/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
if ui.IsTerminalStatus(msg.status) {
// Terminal status detected, trigger completion
return m, func() tea.Msg {
return buildCompleteMsg{status: msg.status}
return buildCompleteMsg{status: msg.status, initError: msg.initError}
}
}

Expand All @@ -506,7 +506,7 @@

// Wait 2 seconds to allow remaining logs to arrive
return m, tea.Tick(2*time.Second, func(t time.Time) tea.Msg {
return logDrainCompleteMsg(msg)
return logDrainCompleteMsg{status: msg.status, initError: msg.initError}

Check failure on line 509 in internal/ui/commands/deploy.go

View workflow job for this annotation

GitHub Actions / golangci-lint

S1016: should convert msg (type buildCompleteMsg) to logDrainCompleteMsg instead of using struct literal (staticcheck)
})

case logDrainCompleteMsg:
Expand Down Expand Up @@ -563,15 +563,23 @@

if m.conf.SimpleOutput() {
fmt.Printf("✗ Build failed with status: %s\n", msg.status)
if msg.initError != nil && *msg.initError != "" {
fmt.Println()
fmt.Println(*msg.initError)
}
return m, tea.Quit
}

// Print error message to scrollback in interactive mode
return m, tea.Sequence(
cmds := []tea.Cmd{
tea.Println(""),
tea.Println(ui.ErrorStyle.Render(fmt.Sprintf("✗ Build failed with status: %s", msg.status))),
tea.Quit,
)
}
if msg.initError != nil && *msg.initError != "" {
cmds = append(cmds, tea.Println(""), tea.Println(*msg.initError))
}
cmds = append(cmds, tea.Quit)
return m, tea.Sequence(cmds...)
}

case confirmationResponseMsg:
Expand Down Expand Up @@ -880,20 +888,23 @@
type zipUploadedMsg struct{}

type buildStatusUpdateMsg struct {
buildID string
status string
buildID string
status string
initError *string
}

type buildStatusPollErrorMsg struct {
err error
}

type buildCompleteMsg struct {
status string
status string
initError *string
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather just use string. The string being empty is sufficient to know that the error is not present, and I don't think we need to distinguish between the zero value and nil here?
The only check checks both:

if msg.initError != nil && *msg.initError != ""

let's just simplify and do

if msg.initError != ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the reason it's tempting (I think) to put a pointer on the type is to be able to distinguish between 'present but empty' and 'not present'. I think that distinction is only useful if there's a functional difference between those two things.

In this case as far as I can tell there is no functional difference so let's just keep it to non-pointer. It makes the type a lot easier to work with

}

type logDrainCompleteMsg struct {
status string // Final build status to use for completion
status string // Final build status to use for completion
initError *string // User-facing error message persisted on the build
}

type buildCancelledMsg struct {
Expand Down Expand Up @@ -1213,8 +1224,9 @@

// Return status update message
return buildStatusUpdateMsg{
buildID: build.Id,
status: build.Status,
buildID: build.Id,
status: build.Status,
initError: build.InitError,
}
}

Expand Down
Loading