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