Skip to content

Commit 40f260a

Browse files
authored
fix: warnings from golangci-lint: S1009 should omit nil check; non-constant format string in call to fmt.Errorf (#849)
Signed-off-by: Cheng Fang <[email protected]>
1 parent b2d8375 commit 40f260a

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

ext/git/writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (m *nativeGitClient) Commit(pathSpec string, opts *CommitOptions) error {
6161

6262
out, err := m.runCmd(args...)
6363
if err != nil {
64-
log.Errorf(out)
64+
log.Errorf("%s %v", out, err)
6565
return err
6666
}
6767

pkg/log/log.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ func (logctx *LogContext) AddField(key string, value interface{}) *LogContext {
7070
return logctx
7171
}
7272

73-
// Logger retrieves the native logger interface. Use with care.
73+
// Log retrieves the native logger interface. Use with care.
7474
func Log() *logrus.Logger {
7575
return logger
7676
}
7777

7878
// Tracef logs a debug message for logctx to stdout
7979
func (logctx *LogContext) Tracef(format string, args ...interface{}) {
8080
logger.SetOutput(logctx.normalOut)
81-
if logctx.fields != nil && len(logctx.fields) > 0 {
81+
if len(logctx.fields) > 0 {
8282
logger.WithFields(logctx.fields).Tracef(format, args...)
8383
} else {
8484
logger.Tracef(format, args...)
@@ -88,7 +88,7 @@ func (logctx *LogContext) Tracef(format string, args ...interface{}) {
8888
// Debugf logs a debug message for logctx to stdout
8989
func (logctx *LogContext) Debugf(format string, args ...interface{}) {
9090
logger.SetOutput(logctx.normalOut)
91-
if logctx.fields != nil && len(logctx.fields) > 0 {
91+
if len(logctx.fields) > 0 {
9292
logger.WithFields(logctx.fields).Debugf(format, args...)
9393
} else {
9494
logger.Debugf(format, args...)
@@ -98,7 +98,7 @@ func (logctx *LogContext) Debugf(format string, args ...interface{}) {
9898
// Infof logs an informational message for logctx to stdout
9999
func (logctx *LogContext) Infof(format string, args ...interface{}) {
100100
logger.SetOutput(logctx.normalOut)
101-
if logctx.fields != nil && len(logctx.fields) > 0 {
101+
if len(logctx.fields) > 0 {
102102
logger.WithFields(logctx.fields).Infof(format, args...)
103103
} else {
104104
logger.Infof(format, args...)
@@ -108,7 +108,7 @@ func (logctx *LogContext) Infof(format string, args ...interface{}) {
108108
// Warnf logs a warning message for logctx to stdout
109109
func (logctx *LogContext) Warnf(format string, args ...interface{}) {
110110
logger.SetOutput(logctx.normalOut)
111-
if logctx.fields != nil && len(logctx.fields) > 0 {
111+
if len(logctx.fields) > 0 {
112112
logger.WithFields(logctx.fields).Warnf(format, args...)
113113
} else {
114114
logger.Warnf(format, args...)
@@ -118,7 +118,7 @@ func (logctx *LogContext) Warnf(format string, args ...interface{}) {
118118
// Errorf logs a non-fatal error message for logctx to stdout
119119
func (logctx *LogContext) Errorf(format string, args ...interface{}) {
120120
logger.SetOutput(logctx.errorOut)
121-
if logctx.fields != nil && len(logctx.fields) > 0 {
121+
if len(logctx.fields) > 0 {
122122
logger.WithFields(logctx.fields).Errorf(format, args...)
123123
} else {
124124
logger.Errorf(format, args...)
@@ -128,14 +128,14 @@ func (logctx *LogContext) Errorf(format string, args ...interface{}) {
128128
// Fatalf logs a fatal error message for logctx to stdout
129129
func (logctx *LogContext) Fatalf(format string, args ...interface{}) {
130130
logger.SetOutput(logctx.errorOut)
131-
if logctx.fields != nil && len(logctx.fields) > 0 {
131+
if len(logctx.fields) > 0 {
132132
logger.WithFields(logctx.fields).Fatalf(format, args...)
133133
} else {
134134
logger.Fatalf(format, args...)
135135
}
136136
}
137137

138-
// Debugf logs a warning message without context to stdout
138+
// Tracef logs a warning message without context to stdout
139139
func Tracef(format string, args ...interface{}) {
140140
logCtx := NewContext()
141141
logCtx.Tracef(format, args...)

0 commit comments

Comments
 (0)