]> git.giacomolli.uk - onechat/blobdiff - journal.go
Add local context to memory operation failures
[onechat] / journal.go
index 745ae790089ec1f5a9bf98debe7e17d212537859..6251e8c7d04b2f38749babc1b3f8b454a26563ea 100644 (file)
@@ -38,13 +38,13 @@ type Journal struct {
 func (j *Journal) Write(day string, line []byte) (Position, error) {
        number, err := journalDayNumber(day)
        if err != nil {
 func (j *Journal) Write(day string, line []byte) (Position, error) {
        number, err := journalDayNumber(day)
        if err != nil {
-               return Position{}, err
+               return Position{}, fmt.Errorf("parse journal day: %w", err)
        }
 
        if number != j.day {
                err = j.closeWriter()
                if err != nil {
        }
 
        if number != j.day {
                err = j.closeWriter()
                if err != nil {
-                       return Position{}, err
+                       return Position{}, fmt.Errorf("close previous day writer: %w", err)
                }
 
                j.file, err = os.OpenFile(filepath.Join(j.dir, day+".jsonl"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
                }
 
                j.file, err = os.OpenFile(filepath.Join(j.dir, day+".jsonl"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o600)
@@ -150,7 +150,7 @@ func (j *Journal) Scan(ctx context.Context, place Position, add func([]byte, Pos
        for n, path := range paths {
                day, err := journalDayNumber(strings.TrimSuffix(filepath.Base(path), ".jsonl"))
                if err != nil {
        for n, path := range paths {
                day, err := journalDayNumber(strings.TrimSuffix(filepath.Base(path), ".jsonl"))
                if err != nil {
-                       return err
+                       return fmt.Errorf("parse day filename: %w", err)
                }
 
                if day < place.day {
                }
 
                if day < place.day {
@@ -164,7 +164,7 @@ func (j *Journal) Scan(ctx context.Context, place Position, add func([]byte, Pos
 
                err = journalScanFile(ctx, path, day, offset, n == len(paths)-1, add)
                if err != nil {
 
                err = journalScanFile(ctx, path, day, offset, n == len(paths)-1, add)
                if err != nil {
-                       return err
+                       return fmt.Errorf("scan day file: %w", err)
                }
        }
 
                }
        }