Skip to content

Commit

Permalink
feat: show errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Mar 17, 2024
1 parent 6ed16fe commit 0c4dc64
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func newModel(envSeq []string, systems []System, outFormat OutFormat, awsConfigS
}
}

errors := make([]error, 0)

return model{
outFormat: outFormat,
results: resultMap,
Expand All @@ -49,5 +51,6 @@ func newModel(envSeq []string, systems []System, outFormat OutFormat, awsConfigS
awsConfigSource: awsConfigSource,
awsConfigs: awsConfigs,
printWhenReady: true,
errors: errors,
}
}
2 changes: 2 additions & 0 deletions ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type model struct {
numResults int
printWhenReady bool
outputPrinted bool
errors []error
terminalWidth int
}

func (m model) Init() tea.Cmd {
Expand Down
7 changes: 7 additions & 0 deletions ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ var (
outOfSyncStylePlain = nonFgStyle.Copy().
Align(lipgloss.Center).
Width(16)

errorHeadingStyle = nonFgStyle.Copy().
Bold(true).
Foreground(lipgloss.Color("#fb4934"))

errorDetailStyle = nonFgStyle.Copy().
Foreground(lipgloss.Color("#665c54"))
)
1 change: 1 addition & 0 deletions ui/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ type HTMLData struct {
Title string
Columns []string
Rows []HTMLDataRow
Errors *[]error
Timestamp string
}
6 changes: 5 additions & 1 deletion ui/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
return m, tea.Quit
case tea.WindowSizeMsg:
m.terminalWidth = msg.Width
case processFinishedMsg:
if msg.err != nil {
m.results[msg.systemKey][msg.env] = string(ErrorFetchingVersion)
m.errors = append(m.errors, msg.err)
errorIndex := len(m.errors)
m.results[msg.systemKey][msg.env] = fmt.Sprintf("%s [%2d]", ErrorFetchingVersion, errorIndex)
} else {
if !msg.found {
m.results[msg.systemKey][msg.env] = string(SystemNotFound)
Expand Down
35 changes: 35 additions & 0 deletions ui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ const (
<br>
<br>
<p class="text-stone-300 italic">Generated at {{.Timestamp}}</p>
{{if .Errors }}
<br>
<hr>
<br>
<p class="text-red-600 font-bold italic">Errors</p>
<br>
{{range $index, $error := .Errors -}}
<p class="text-gray-400 italic">{{$index}}: {{$error}}</p>
<br>
{{end -}}
{{end -}}
</div>
</body>
</html>
Expand Down Expand Up @@ -100,6 +112,16 @@ func (m model) renderPlainText() string {
}
s += "\n"
}

if len(m.errors) > 0 {
s += "\n"
s += "Errors"
s += "\n"
for index, err := range m.errors {
s += fmt.Sprintf("[%2d]: %s", index+1, err.Error())
s += "\n"
}
}
return s
}

Expand Down Expand Up @@ -140,6 +162,9 @@ func (m model) renderHTML() string {
}
data.Columns = columns
data.Rows = rows
if len(m.errors) > 0 {
data.Errors = &m.errors
}
data.Timestamp = time.Now().Format("2006-01-02 15:04:05 MST")

tmpl, err := template.New("ecsv").Parse(templateText)
Expand Down Expand Up @@ -186,6 +211,16 @@ func (m model) renderCLIUI() string {
}
s += "\n"
}

if len(m.errors) > 0 {
s += "\n"
s += errorHeadingStyle.Render("Errors")
s += "\n"
for index, err := range m.errors {
s += errorDetailStyle.Render(fmt.Sprintf("[%2d]: %s", index+1, err.Error()))
s += "\n"
}
}
return s
}

Expand Down

0 comments on commit 0c4dc64

Please # to comment.