Skip to content

Commit 6204cd1

Browse files
committed
fix: surface errors
1 parent c000e41 commit 6204cd1

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

runner/sidecar/sidecar.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func patchStepStatus(ctx context.Context) {
138138
"sinkStatuses": sinkStatues,
139139
},
140140
})
141-
logger.Info("patching step status (sinks/sources)", "patch", patch)
141+
debug.Info("patching step status (sinks/sources)", "patch", patch)
142142
if _, err := dynamicInterface.
143143
Resource(dfv1.StepGroupVersionResource).
144144
Namespace(namespace).
@@ -348,6 +348,7 @@ func connectSources(ctx context.Context, toMain func([]byte) error) error {
348348
if err != nil {
349349
logger.Error(err, "⚠ http →")
350350
w.WriteHeader(500)
351+
_, _ = w.Write([]byte(err.Error()))
351352
withLock(func() { sourceStatues.IncErrors(sourceName, replica, err) })
352353
return
353354
}
@@ -356,6 +357,7 @@ func connectSources(ctx context.Context, toMain func([]byte) error) error {
356357
if err := toMain(data); err != nil {
357358
logger.Error(err, "⚠ http →")
358359
w.WriteHeader(500)
360+
_, _ = w.Write([]byte(err.Error()))
359361
withLock(func() { sourceStatues.IncErrors(sourceName, replica, err) })
360362
} else {
361363
debug.Info("✔ http ")
@@ -435,7 +437,8 @@ func connectTo(ctx context.Context) (func([]byte) error, error) {
435437
return fmt.Errorf("failed to send message to main via HTTP: %w", err)
436438
}
437439
if resp.StatusCode >= 300 {
438-
return fmt.Errorf("failed to sent message to main via HTTP: %s", resp.Status)
440+
body, _ := ioutil.ReadAll(resp.Body)
441+
return fmt.Errorf("failed to sent message to main via HTTP: %q %q", resp.Status, body)
439442
}
440443
trace.Info("✔ source → http")
441444
return nil
@@ -480,16 +483,18 @@ func connectOut(toSink func([]byte) error) {
480483
if err != nil {
481484
logger.Error(err, "failed to read message body from main via HTTP")
482485
w.WriteHeader(500)
486+
_, _ = w.Write([]byte(err.Error()))
483487
return
484488
}
485489
trace.Info("◷ http → sink")
486490
if err := toSink(data); err != nil {
487491
logger.Error(err, "failed to send message from main to sink")
488492
w.WriteHeader(500)
489-
return
493+
_, _ = w.Write([]byte(err.Error()))
494+
} else {
495+
trace.Info("✔ http → sink")
496+
w.WriteHeader(200)
490497
}
491-
trace.Info("✔ http → sink")
492-
w.WriteHeader(200)
493498
})
494499
go func() {
495500
defer runtimeutil.HandleCrash(runtimeutil.PanicHandlers...)
@@ -561,8 +566,9 @@ func connectSink() (func([]byte) error, error) {
561566
err := func() error {
562567
if resp, err := http.Post(x.URL, "application/octet-stream", bytes.NewBuffer(m)); err != nil {
563568
return err
564-
} else if resp.StatusCode != 200 {
565-
return fmt.Errorf("failed to send HTTP request: %q", resp.Status)
569+
} else if resp.StatusCode >= 300 {
570+
body, _ := ioutil.ReadAll(resp.Body)
571+
return fmt.Errorf("failed to send HTTP request: %q %q", resp.Status, body)
566572
} else {
567573
return nil
568574
}

0 commit comments

Comments
 (0)