Fix linter warnings about ignoring errors from bufio.Scanner

This commit is contained in:
Stefan Haller 2026-05-03 16:38:03 +02:00
parent 562d0541a1
commit 8dbdd74400
6 changed files with 23 additions and 6 deletions

View file

@ -79,6 +79,10 @@ func (self *SubmoduleCommands) GetConfigs(parentModule *models.SubmoduleConfig)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return configs, nil
}

View file

@ -392,6 +392,10 @@ func (self *cmdObjRunner) processOutput(
}
}
}
if err := scanner.Err(); err != nil {
self.log.Error(err)
}
}
// having a function that returns a function because we need to maintain some state inbetween calls hence the closure

View file

@ -93,11 +93,11 @@ func FileHasConflictMarkers(path string) (bool, error) {
defer file.Close()
return fileHasConflictMarkersAux(file), nil
return fileHasConflictMarkersAux(file)
}
// Efficiently scans through a file looking for merge conflict markers. Returns true if it does
func fileHasConflictMarkersAux(file io.Reader) bool {
func fileHasConflictMarkersAux(file io.Reader) (bool, error) {
scanner := bufio.NewScanner(file)
scanner.Split(utils.ScanLinesAndTruncateWhenLongerThanBuffer(bufio.MaxScanTokenSize))
for scanner.Scan() {
@ -105,13 +105,13 @@ func fileHasConflictMarkersAux(file io.Reader) bool {
// only searching for start/end markers because the others are more ambiguous
if bytes.HasPrefix(line, CONFLICT_START_BYTES) {
return true
return true, nil
}
if bytes.HasPrefix(line, CONFLICT_END_BYTES) {
return true
return true, nil
}
}
return false
return false, scanner.Err()
}

View file

@ -96,6 +96,8 @@ func TestFindConflictsAux(t *testing.T) {
for _, s := range scenarios {
reader := strings.NewReader(s.content)
assert.EqualValues(t, s.expected, fileHasConflictMarkersAux(reader))
result, err := fileHasConflictMarkersAux(reader)
assert.NoError(t, err)
assert.EqualValues(t, s.expected, result)
}
}

View file

@ -55,6 +55,9 @@ func tailFrom(lastOffset int64, logFilePath string, opts *humanlog.HandlerOption
lines = append(lines, fileScanner.Text())
}
file.Close()
if err := fileScanner.Err(); err != nil {
return err
}
lineCount := len(lines)
lastTen := lines
if lineCount > 10 {

View file

@ -210,6 +210,10 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
<-lineWrittenChan
}
}
if err := scanner.Err(); err != nil {
self.Log.Error(err)
}
})
loaded := false