Fix linter warnings about ignoring errors from bufio.Scanner

This commit is contained in:
Stefan Haller committed 2026-05-03 16:57:24 +02:00
1 parent 562d0541a1
commit 8dbdd74400
6 files changed
+23 -6

No files matched your search

+4
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
}
@@ -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
+5 -5
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()
}
@@ -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)
}
}
+3
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 {
+4
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