Skip to content

Commit b73ee83

Browse files
Update error handling (#289)
* Update error handling * Fix typo Co-authored-by: Phil <[email protected]> --------- Co-authored-by: Phil <[email protected]>
1 parent f96d179 commit b73ee83

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

op-batcher/batcher/espresso.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package batcher
22

33
import (
4+
"errors"
45
"fmt"
5-
"strings"
66
"time"
77

88
"context"
@@ -210,16 +210,13 @@ const (
210210
Skip
211211
)
212212

213-
// TODO (Keyao) Update the espresso-network-go repo for better error handling.
214-
// <https://app.asana.com/1/1208976916964769/project/1209392461754458/task/1210405729138484?focus=true>
215-
//
216213
// Evaluate the submission job.
217214
//
218215
// # Returns
219216
//
220217
// * If there is no error: Handle.
221218
//
222-
// * If there is an issue on our side: Skip.
219+
// * If there is a permanent issue that won't be fixed by a retry: Skip.
223220
//
224221
// * Otherwise: RetrySubmission.
225222
func evaluateSubmission(jobResp espressoSubmitTransactionJobResponse) JobEvaluation {
@@ -230,25 +227,13 @@ func evaluateSubmission(jobResp espressoSubmitTransactionJobResponse) JobEvaluat
230227
return Handle
231228
}
232229

233-
msg := err.Error()
234-
235-
// If the transaction is invalid due to a JSON error, skip the submission.
236-
if strings.Contains(msg, "json: unsupported type:") ||
237-
strings.Contains(msg, "json: unsupported value:") ||
238-
strings.Contains(msg, "json: error calling") ||
239-
strings.Contains(msg, "json: invalid UTF-8 in string") ||
240-
strings.Contains(msg, "json: invalid number literal") ||
241-
strings.Contains(msg, "json: encoding error for type") {
242-
log.Warn("json.Marshal fails, skipping", "msg", msg)
230+
if errors.Is(err, espressoClient.ErrPermanent) {
243231
return Skip
244232
}
245233

246-
// If the request is invalid (likely due to API change), skip the submission.
247-
if strings.Contains(msg, "net/http: nil Context") ||
248-
strings.Contains(msg, "net/http: invalid method") ||
249-
strings.HasPrefix(msg, "parse ") {
250-
log.Warn("NewRequestWithContext fails, skipping", "msg", msg)
251-
return Skip
234+
if !errors.Is(err, espressoClient.ErrEphemeral) {
235+
// Log the warning for a potentially missed error handling, but still retry it.
236+
log.Warn("error not explicitly marked as retryable or not", "err", err)
252237
}
253238

254239
// Otherwise, retry the submission.
@@ -319,16 +304,13 @@ const VERIFY_RECEIPT_TIMEOUT = 4 * time.Second
319304
// retrying a job that failed to verify the receipt.
320305
const VERIFY_RECEIPT_RETRY_DELAY = 100 * time.Millisecond
321306

322-
// TODO (Keyao) Update the espresso-network-go repo for better error handling.
323-
// <https://app.asana.com/1/1208976916964769/project/1209392461754458/task/1210405729138484?focus=true>
324-
//
325307
// Evaluate the verification job.
326308
//
327309
// # Returns
328310
//
329311
// * If there is no error: Handle.
330312
//
331-
// * If there is an issue on our side: Skip.
313+
// * If there is a permanent issue that won't be fixed by a retry: Skip.
332314
//
333315
// * If the verification times out: RetrySubmission.
334316
//
@@ -341,12 +323,15 @@ func evaluateVerification(jobResp espressoVerifyReceiptJobResponse) JobEvaluatio
341323
return Handle
342324
}
343325

344-
// If the hash is invalid, skip the verification.
345-
if strings.Contains(err.Error(), "hash is nil") {
346-
log.Warn("Hash is nil, skipping")
326+
if errors.Is(err, espressoClient.ErrPermanent) {
347327
return Skip
348328
}
349329

330+
if !errors.Is(err, espressoClient.ErrEphemeral) {
331+
// Log the warning for a potentially missed error handling, but still retry it.
332+
log.Warn("error not explicitly marked as retryable or not", "err", err)
333+
}
334+
350335
// If the verification times out, degrade to the submission phase and try again.
351336
if have := time.Now(); have.Sub(jobResp.job.start) > VERIFY_RECEIPT_TIMEOUT {
352337
return RetrySubmission

0 commit comments

Comments
 (0)