Skip to content

Commit 7dea6df

Browse files
jbedardCopilot
andauthored
refactor: propogate watch connection errors (#123)
### Changes are visible to end-users: no ### Test plan - Covered by existing test cases --------- Co-authored-by: Copilot <[email protected]>
1 parent 8e32503 commit 7dea6df

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

runner/pkg/ibp/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
visibility = ["//visibility:public"],
1111
deps = [
1212
"//pkg/socket",
13+
"@aspect_gazelle//common/logger",
1314
"@com_github_fatih_color//:color",
1415
],
1516
)

runner/pkg/ibp/client.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"iter"
66
"slices"
77

8+
BazelLog "github.com/aspect-build/aspect-gazelle/common/logger"
89
"github.com/aspect-build/aspect-gazelle/runner/pkg/socket"
910
)
1011

1112
type IncrementalClient interface {
1213
Connect() error
1314
Disconnect() error
14-
AwaitCycle() iter.Seq[CycleSourcesMessage]
15+
AwaitCycle() iter.Seq2[*CycleSourcesMessage, error]
1516
}
1617

1718
type incClient struct {
@@ -84,12 +85,13 @@ func (c *incClient) Disconnect() error {
8485
return err
8586
}
8687

87-
func (c *incClient) AwaitCycle() iter.Seq[CycleSourcesMessage] {
88-
return func(yield func(CycleSourcesMessage) bool) {
88+
func (c *incClient) AwaitCycle() iter.Seq2[*CycleSourcesMessage, error] {
89+
return func(yield func(*CycleSourcesMessage, error) bool) {
8990
for {
9091
msg, err := c.socket.Recv()
9192
if err != nil {
9293
fmt.Printf("Error receiving message: %v\n", err)
94+
yield(nil, err)
9395
return
9496
}
9597

@@ -100,21 +102,28 @@ func (c *incClient) AwaitCycle() iter.Seq[CycleSourcesMessage] {
100102
continue
101103
}
102104

103-
c.socket.Send(CycleMessage{
105+
err := c.socket.Send(CycleMessage{
104106
Message: Message{
105107
Kind: "CYCLE_STARTED",
106108
},
107109
CycleId: cycleEvent.CycleId,
108110
})
111+
if err != nil {
112+
yield(nil, err)
113+
return
114+
}
109115

110-
r := yield(cycleEvent)
116+
r := yield(&cycleEvent, nil)
111117

112-
c.socket.Send(CycleMessage{
118+
err = c.socket.Send(CycleMessage{
113119
Message: Message{
114120
Kind: "CYCLE_COMPLETED",
115121
},
116122
CycleId: cycleEvent.CycleId,
117123
})
124+
if err != nil {
125+
BazelLog.Warnf("Failed to send CYCLE_COMPLETED for cycle_id=%d: %v\n", cycleEvent.CycleId, err)
126+
}
118127

119128
if !r {
120129
return

runner/runner.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ func (p *GazelleRunner) Watch(watchAddress string, cmd GazelleCommand, mode Gaze
239239
defer t.End()
240240

241241
// Subscribe to further changes
242-
for cs := range watch.AwaitCycle() {
242+
for cs, err := range watch.AwaitCycle() {
243+
if err != nil {
244+
fmt.Printf("ERROR: watch cycle error: %v\n", err)
245+
return err
246+
}
247+
243248
_, t := p.tracer.Start(ctx, "GazelleRunner.Watch.Trigger")
244249

245250
// The directories that have changed which gazelle should update.

0 commit comments

Comments
 (0)