X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/d8f3785bb69288663f4cc46bf4d609c6770452d5..4a42f7f208cbfead335eba9ebe615b35b1742130:/log.go diff --git a/log.go b/log.go index 1ed70e7..61f4d4c 100644 --- a/log.go +++ b/log.go @@ -65,7 +65,7 @@ func openLog(ctx context.Context, root string, clock func() time.Time) (*Log, er lock, err := lockFile(filepath.Join(root, "lock")) if err != nil { - return nil, err + return nil, fmt.Errorf("lock message log: %w", err) } l := &Log{ @@ -111,7 +111,7 @@ func (l *Log) catchUp(ctx context.Context) error { if l.index.count > 0 { record, _, err := l.index.Read(l.index.count - 1) if err != nil { - return err + return fmt.Errorf("read last log position: %w", err) } last := decodePosition(record) @@ -121,7 +121,7 @@ func (l *Log) catchUp(ctx context.Context) error { } } - return l.journal.Scan(ctx, start, func(line []byte, place Position) error { + err := l.journal.Scan(ctx, start, func(line []byte, place Position) error { var message Message err := json.Unmarshal(line, &message) @@ -138,8 +138,18 @@ func (l *Log) catchUp(ctx context.Context) error { return fmt.Errorf("message %d: %w", message.ID, err) } - return l.addIndex(place) + err = l.addIndex(place) + if err != nil { + return fmt.Errorf("index scanned message: %w", err) + } + + return nil }) + if err != nil { + return fmt.Errorf("scan message journal: %w", err) + } + + return nil } func (l *Log) addIndex(place Position) error { @@ -220,7 +230,7 @@ func (l *Log) Len() int { func (l *Log) Message(id int) (Message, error) { record, found, err := l.index.Read(id) if err != nil { - return Message{}, err + return Message{}, fmt.Errorf("read message position: %w", err) } if !found {