Skip to content

Commit 2dc3177

Browse files
committed
feat: add Error field and improve logging
Add Error field to GolangCILintResult struct for better error handling. Improve logging by: - Adding Debugf method to logger interface - Adding early return after logging JSON marshal errors - Replacing DebugJSON with Debugf for improved command visibility - Standardizing printf formatting with explicit newlines
1 parent cb03c97 commit 2dc3177

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

golangci-lint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ type GolangCILintResult struct {
5151
Enabled bool `json:"Enabled"`
5252
EnabledByDefault bool `json:"EnabledByDefault,omitempty"`
5353
} `json:"Linters"`
54+
Error string `json:"Error"`
5455
} `json:"Report"`
5556
}

handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
6464
} else {
6565
cmd.Dir = dir
6666
}
67-
h.logger.DebugJSON("golangci-lint-langserver: golingci-lint cmd", cmd)
67+
h.logger.Debugf("golangci-lint-langserver: golingci-lint cmd: %v\n", cmd)
6868

6969
b, err := cmd.Output()
7070
if err == nil {
@@ -134,7 +134,7 @@ func (h *langHandler) linter() {
134134

135135
diagnostics, err := h.lint(uri)
136136
if err != nil {
137-
h.logger.Printf("%s", err)
137+
h.logger.Printf("%s\n", err)
138138

139139
continue
140140
}
@@ -146,7 +146,7 @@ func (h *langHandler) linter() {
146146
URI: uri,
147147
Diagnostics: diagnostics,
148148
}); err != nil {
149-
h.logger.Printf("%s", err)
149+
h.logger.Printf("%s\n", err)
150150
}
151151
}
152152
}

logger.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var _ logger = (*stdLogger)(nil)
1010

1111
type logger interface {
1212
Printf(format string, args ...interface{})
13+
Debugf(format string, args ...interface{})
1314
DebugJSON(label string, arg interface{})
1415
}
1516

@@ -29,6 +30,10 @@ func (l *stdLogger) Printf(format string, args ...interface{}) {
2930
l.stderr.Printf(format, args...)
3031
}
3132

33+
func (l *stdLogger) Debugf(format string, args ...interface{}) {
34+
l.stderr.Printf(format, args...)
35+
}
36+
3237
func (l *stdLogger) DebugJSON(label string, arg interface{}) {
3338
if !l.debug {
3439
return
@@ -37,6 +42,7 @@ func (l *stdLogger) DebugJSON(label string, arg interface{}) {
3742
b, err := json.Marshal(arg)
3843
if err != nil {
3944
l.stderr.Println(err)
45+
return
4046
}
4147

4248
l.stderr.Println(label, string(b))

0 commit comments

Comments
 (0)