Skip to content

Commit

Permalink
fix: log end Line out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
tr1v3r committed Jul 13, 2022
1 parent 6d124a4 commit d0aaca1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,18 @@ func (g *Generator) fillModelPkgPath(filePath string) {
func (g *Generator) output(fileName string, content []byte) error {
result, err := imports.Process(fileName, content, nil)
if err != nil {
line := strings.Split(string(content), "\n")
lines := strings.Split(string(content), "\n")
errLine, _ := strconv.Atoi(strings.Split(err.Error(), ":")[1])
startLine, endLine := errLine-5, errLine+5
fmt.Println("Format fail:", errLine, err)
if startLine < 0 {
startLine = 0
}
if endLine > len(lines)-1 {
endLine = len(lines) - 1
}
for i := startLine; i <= endLine; i++ {
fmt.Println(i, line[i])
fmt.Println(i, lines[i])
}
return fmt.Errorf("cannot format file: %w", err)
}
Expand Down

0 comments on commit d0aaca1

Please sign in to comment.