From 22ec6a961e0d2d61fa274efd3fee16211938ebc3 Mon Sep 17 00:00:00 2001
From: Sarah Jamie Lewis <sarah@openprivacy.ca>
Date: Sat, 15 Feb 2025 16:24:43 -0800
Subject: [PATCH 1/1] Improve Comments on common/log

---
 common/log.go | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/common/log.go b/common/log.go
index ff519e2..77c157e 100644
--- a/common/log.go
+++ b/common/log.go
@@ -21,6 +21,9 @@ type LogEntry struct {
 
 type Log []LogEntry
 
+// senary keeps issues and change requests on-disk and maintains a log of actions over these artifacts i.e. created, approved or deleted.
+// logs can in theory be "collapsed" by permanently deleting create and approved entries if a deleted entry also exists
+// we don't do this here, but may want to build a standalone command to do this in the future.
 func WriteToLog(filename string, hash string, t LogType) error {
 	file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
 	if err != nil {
@@ -31,6 +34,7 @@ func WriteToLog(filename string, hash string, t LogType) error {
 	return err
 }
 
+// iterate over each log entry and callback to the provided function
 func LogIer(filename string, callback func(LogEntry)) error {
 	file, err := os.Open(filename)
 	if err != nil {
@@ -39,11 +43,15 @@ func LogIer(filename string, callback func(LogEntry)) error {
 	defer file.Close()
 
 	scanner := bufio.NewScanner(file)
-	// optionally, resize scanner's capacity for lines over 64K, see next example
 	for scanner.Scan() {
 		logline := scanner.Text()
 		logEntry := LogEntry{}
-		fmt.Sscanf(logline, "%s %d", &logEntry.Hash, &logEntry.Type)
+		n, err := fmt.Sscanf(logline, "%s %d", &logEntry.Hash, &logEntry.Type)
+
+		// corrupted or malformed log entry, we can't recover from this so abort...
+		if n != 2 || err != nil {
+			return err
+		}
 		callback(logEntry)
 	}
 
-- 
2.43.0

