Skip to content

Commit 40898d3

Browse files
authored
Refine err msg in SetOffsetAt() (#1001)
1 parent bef2911 commit 40898d3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

reader.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,12 +1083,16 @@ func (r *Reader) SetOffsetAt(ctx context.Context, t time.Time) error {
10831083
}
10841084
r.mutex.Unlock()
10851085

1086+
if len(r.config.Brokers) < 1 {
1087+
return errors.New("no brokers in config")
1088+
}
1089+
var conn *Conn
1090+
var err error
10861091
for _, broker := range r.config.Brokers {
1087-
conn, err := r.config.Dialer.DialLeader(ctx, "tcp", broker, r.config.Topic, r.config.Partition)
1092+
conn, err = r.config.Dialer.DialLeader(ctx, "tcp", broker, r.config.Topic, r.config.Partition)
10881093
if err != nil {
10891094
continue
10901095
}
1091-
10921096
deadline, _ := ctx.Deadline()
10931097
conn.SetDeadline(deadline)
10941098
offset, err := conn.ReadOffset(t)
@@ -1099,7 +1103,7 @@ func (r *Reader) SetOffsetAt(ctx context.Context, t time.Time) error {
10991103

11001104
return r.SetOffset(offset)
11011105
}
1102-
return fmt.Errorf("error setting offset for timestamp %+v", t)
1106+
return fmt.Errorf("error dialing all brokers, one of the errors: %w", err)
11031107
}
11041108

11051109
// Stats returns a snapshot of the reader stats since the last time the method

0 commit comments

Comments
 (0)