Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 64aa1c1

Browse files
committed
fixup! Migrate more logs to clog
1 parent d403878 commit 64aa1c1

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

internal/clog/error.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ import (
1010
"golang.org/x/xerrors"
1111
)
1212

13-
// RichCLIMessage provides a human-readable message for CLI errors and messages.
14-
type RichCLIMessage struct {
13+
// CLIMessage provides a human-readable message for CLI errors and messages.
14+
type CLIMessage struct {
1515
Level string
1616
Color color.Attribute
1717
Header string
1818
Lines []string
1919
}
2020

21-
// RichCLIError wraps a RichCLIMessage a allows consumers to treat it as a normal error.
22-
type RichCLIError struct {
23-
RichCLIMessage
21+
// CLIError wraps a RichCLIMessage a allows consumers to treat it as a normal error.
22+
type CLIError struct {
23+
CLIMessage
2424
error
2525
}
2626

2727
// Error formats the CLI message for consumption by a human as an error.
28-
func (r RichCLIMessage) String() string {
28+
func (r CLIMessage) String() string {
2929
var str strings.Builder
3030
str.WriteString(fmt.Sprintf("%s: %s\n",
3131
color.New(r.Color).Sprint(r.Level),
@@ -41,7 +41,7 @@ func (r RichCLIMessage) String() string {
4141
// If the error is a RichCLIError, the plain error chain is ignored and the rich error
4242
// is logged on its own.
4343
func Log(err error) {
44-
var cliErr RichCLIError
44+
var cliErr CLIError
4545
if !xerrors.As(err, &cliErr) {
4646
cliErr = Fatal(err.Error())
4747
}
@@ -50,7 +50,7 @@ func Log(err error) {
5050

5151
// LogInfo prints the given info message to stderr.
5252
func LogInfo(header string, lines ...string) {
53-
fmt.Fprintln(os.Stderr, RichCLIMessage{
53+
fmt.Fprintln(os.Stderr, CLIMessage{
5454
Level: "info",
5555
Color: color.FgBlue,
5656
Header: header,
@@ -65,7 +65,7 @@ func F(format string, a ...interface{}) string {
6565

6666
// LogSuccess prints the given info message to stderr.
6767
func LogSuccess(header string, lines ...string) {
68-
fmt.Fprintln(os.Stderr, RichCLIMessage{
68+
fmt.Fprintln(os.Stderr, CLIMessage{
6969
Level: "success",
7070
Color: color.FgGreen,
7171
Header: header,
@@ -74,9 +74,9 @@ func LogSuccess(header string, lines ...string) {
7474
}
7575

7676
// Warn creates an error with the level "warning".
77-
func Warn(header string, lines ...string) RichCLIError {
78-
return RichCLIError{
79-
RichCLIMessage: RichCLIMessage{
77+
func Warn(header string, lines ...string) CLIError {
78+
return CLIError{
79+
RichCLIMessage: CLIMessage{
8080
Color: color.FgYellow,
8181
Level: "warning",
8282
Header: header,
@@ -87,9 +87,9 @@ func Warn(header string, lines ...string) RichCLIError {
8787
}
8888

8989
// Error creates an error with the level "error".
90-
func Error(header string, lines ...string) RichCLIError {
91-
return RichCLIError{
92-
RichCLIMessage: RichCLIMessage{
90+
func Error(header string, lines ...string) CLIError {
91+
return CLIError{
92+
RichCLIMessage: CLIMessage{
9393
Color: color.FgRed,
9494
Level: "error",
9595
Header: header,
@@ -100,9 +100,9 @@ func Error(header string, lines ...string) RichCLIError {
100100
}
101101

102102
// Fatal creates an error with the level "fatal".
103-
func Fatal(header string, lines ...string) RichCLIError {
104-
return RichCLIError{
105-
RichCLIMessage: RichCLIMessage{
103+
func Fatal(header string, lines ...string) CLIError {
104+
return CLIError{
105+
RichCLIMessage: CLIMessage{
106106
Color: color.FgRed,
107107
Level: "fatal",
108108
Header: header,

0 commit comments

Comments
 (0)