@@ -18,11 +18,11 @@ type Data struct {
1818 Choices []Choice `json:"choices"`
1919}
2020
21- func ParseFile (filename string ) error {
21+ func ParseFile (filename string ) ( string , error ) {
2222 // Open the file
2323 file , err := os .Open (filename )
2424 if err != nil {
25- return fmt .Errorf ("could not open file: %w" , err )
25+ return "" , fmt .Errorf ("could not open file: %w" , err )
2626 }
2727 defer file .Close ()
2828
@@ -52,8 +52,7 @@ func ParseFile(filename string) error {
5252 var data Data
5353 err := json .Unmarshal ([]byte (line ), & data )
5454 if err != nil {
55- // Skip this line if JSON is incomplete or malformed
56- continue
55+ return "" , fmt .Errorf ("error parsing JSON: %w" , err )
5756 }
5857
5958 // Extract delta.content and concatenate it
@@ -64,12 +63,10 @@ func ParseFile(filename string) error {
6463
6564 // Check for scanner errors
6665 if err := scanner .Err (); err != nil {
67- return fmt .Errorf ("error reading file: %w" , err )
66+ return "" , fmt .Errorf ("error reading file: %w" , err )
6867 }
6968
7069 // Print the final concatenated result
7170 result := contentBuilder .String ()
72- fmt .Println (result )
73-
74- return nil
71+ return result , nil
7572}
0 commit comments