feat: return error on Atoi failed
This commit is contained in:
parent
0cf87fa332
commit
d76fe99811
|
@ -2,6 +2,7 @@
|
|||
package clangtidy
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -78,8 +79,16 @@ func parseMessage(line string) ClangMessage {
|
|||
return *newClangMessage("", 0, 0, UNKNOWN, "", "", nil, nil)
|
||||
} else {
|
||||
filepath := regexRes[1]
|
||||
line, _ := strconv.Atoi(regexRes[2])
|
||||
column, _ := strconv.Atoi(regexRes[3])
|
||||
line, err := strconv.Atoi(regexRes[2])
|
||||
if err != nil {
|
||||
line = 0
|
||||
slog.Error("parse line", "error", err)
|
||||
}
|
||||
column, err := strconv.Atoi(regexRes[3])
|
||||
if err != nil {
|
||||
column = 0
|
||||
slog.Error("parse column", "error", err)
|
||||
}
|
||||
level := levelFromString(regexRes[4])
|
||||
message := regexRes[5]
|
||||
diagnosticName := regexRes[6]
|
||||
|
|
|
@ -2,6 +2,7 @@ package cpplint
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
|
@ -23,10 +24,24 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
|
|||
comment := ""
|
||||
for _, match := range matches {
|
||||
fileName := match[1]
|
||||
lineNum, _ := strconv.Atoi(match[2])
|
||||
lineNum, err := strconv.Atoi(match[2])
|
||||
if err != nil {
|
||||
slog.Error("parse lineNum", "error", err)
|
||||
return stage.ParserResult{
|
||||
Score: 0,
|
||||
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
||||
}
|
||||
}
|
||||
message := match[3]
|
||||
category := match[4]
|
||||
confidence, _ := strconv.Atoi(match[5])
|
||||
confidence, err := strconv.Atoi(match[5])
|
||||
if err != nil {
|
||||
slog.Error("parse confidence", "error", err)
|
||||
return stage.ParserResult{
|
||||
Score: 0,
|
||||
Comment: fmt.Sprintf("Unexpected parser error: %s.", err),
|
||||
}
|
||||
}
|
||||
score -= confidence
|
||||
// TODO: add more detailed comment, just re-assemble for now
|
||||
comment += fmt.Sprintf("%s:%d: %s [%s] [%d]\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user