Skip to content

Commit 97deb1b

Browse files
committed
Fix colons and clean up code
1 parent 0612a27 commit 97deb1b

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

cli/root.go

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -824,53 +824,50 @@ type prettyErrorFormatter struct {
824824

825825
func (p *prettyErrorFormatter) format(err error) {
826826
if err == nil {
827-
// 🍒
827+
// 🏁
828828
p.printf("\n")
829829
return
830830
}
831831

832-
underErr := errors.Unwrap(err)
832+
nextErr := errors.Unwrap(err)
833833

834834
//nolint:errorlint
835-
if _, ok := err.(*clibase.RunCommandError); ok && p.level == 0 && underErr != nil {
836-
// We can do a better job now.
837-
p.format(underErr)
835+
if _, ok := err.(*clibase.RunCommandError); ok && p.level == 0 && nextErr != nil {
836+
// Avoid extra nesting.
837+
p.format(nextErr)
838838
return
839839
}
840840

841-
errorWithoutChildren := err.Error()
842-
if underErr != nil {
843-
errorWithoutChildren = strings.TrimSuffix(err.Error(), ": "+underErr.Error())
841+
var headErr string
842+
if nextErr != nil {
843+
headErr = strings.TrimSuffix(err.Error(), ": "+nextErr.Error())
844+
} else {
845+
headErr = err.Error()
844846
}
845847

846-
// Format the root error specially since it's the most relevant.
847-
if p.level == 0 {
848-
textStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#D16644")).Bold(false)
849-
var msg string
850-
var sdkError *codersdk.Error
851-
if errors.As(err, &sdkError) {
852-
msg = sdkError.Message + sdkError.Helper
853-
} else {
854-
msg = errorWithoutChildren
855-
}
856-
p.printf(
857-
"%s",
858-
textStyle.Render(msg),
859-
)
848+
var msg string
849+
var sdkError *codersdk.Error
850+
if errors.As(err, &sdkError) {
851+
msg = sdkError.Message + sdkError.Helper
852+
} else {
853+
msg = headErr
854+
}
860855

861-
p.level++
862-
p.format(underErr)
863-
return
856+
textStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#D16644"))
857+
if p.level > 0 {
858+
textStyle.Foreground(lipgloss.Color("#969696"))
864859
}
865860

866-
textStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#969696")).Bold(false)
861+
if nextErr != nil {
862+
msg = msg + ": "
863+
}
867864

868865
p.printf(
869866
"%s",
870-
textStyle.Render(": "+errorWithoutChildren),
867+
textStyle.Render(msg),
871868
)
872869
p.level++
873-
p.format(underErr)
870+
p.format(nextErr)
874871
}
875872

876873
func (p *prettyErrorFormatter) printf(format string, a ...interface{}) {

0 commit comments

Comments
 (0)