1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-07-27 17:28:35 +00:00

chore: refactor Report{Log,State} retry errors

Introduce ErrRetry to distinguish errors that are wort a retry from
the others.
This commit is contained in:
Earl Warren 2025-07-05 10:50:44 +02:00
parent 7ccc32744a
commit 45fae19e5b
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -256,6 +256,28 @@ func (r *Reporter) Close(lastWords string) error {
}, retry.Context(r.ctx))
}
type ErrRetry struct {
message string
}
func (err ErrRetry) Error() string {
return err.message
}
func (err ErrRetry) Is(target error) bool {
_, ok := target.(*ErrRetry)
return ok
}
var (
errRetryNeedMoreRows = "need more rows to figure out if multiline secrets must be masked"
errRetrySendAll = "not all logs are submitted %d remain"
)
func NewErrRetry(message string, args ...any) error {
return &ErrRetry{message: fmt.Sprintf(message, args...)}
}
func (r *Reporter) ReportLog(noMore bool) error {
r.clientM.Lock()
defer r.clientM.Unlock()
@ -280,7 +302,7 @@ func (r *Reporter) ReportLog(noMore bool) error {
ack := int(resp.Msg.AckIndex)
if ack < r.logOffset {
return fmt.Errorf("submitted logs are lost")
return fmt.Errorf("submitted logs are lost %d < %d", ack, r.logOffset)
}
r.stateMu.Lock()
@ -289,7 +311,7 @@ func (r *Reporter) ReportLog(noMore bool) error {
r.stateMu.Unlock()
if noMore && ack < r.logOffset+len(rows) {
return fmt.Errorf("not all logs are submitted")
return NewErrRetry(errRetrySendAll, len(r.logRows))
}
return nil
@ -335,7 +357,7 @@ func (r *Reporter) ReportState() error {
return true
})
if len(noSent) > 0 {
return fmt.Errorf("there are still outputs that have not been sent: %v", noSent)
return NewErrRetry(errRetrySendAll, len(noSent))
}
return nil