mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(oplog): use json.Decoder to handle arbitrarily large JSONL lines
Replace bufio.Scanner with json.NewDecoder which has no fixed line length limit. Fixes "token too long" crash when audit results produce JSONL entries exceeding the 64KB scanner default.
This commit is contained in:
+8
-12
@@ -3,7 +3,6 @@
|
||||
package oplog
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -92,21 +91,18 @@ func Read(configPath, filename string, limit int) ([]Entry, error) {
|
||||
defer f.Close()
|
||||
|
||||
var all []Entry
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Bytes()
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
dec := json.NewDecoder(f)
|
||||
for dec.More() {
|
||||
var e Entry
|
||||
if err := json.Unmarshal(line, &e); err != nil {
|
||||
continue // skip malformed lines
|
||||
if err := dec.Decode(&e); err != nil {
|
||||
// Skip malformed entries — advance past the bad line
|
||||
if dec.More() {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
all = append(all, e)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Reverse to newest-first
|
||||
for i, j := 0, len(all)-1; i < j; i, j = i+1, j-1 {
|
||||
|
||||
Reference in New Issue
Block a user