Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/servers/destinations.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,23 @@ func (s *DestinationServer) Write2(msg pb.Destination_Write2Server) error {
if err == io.EOF {
close(resources)
if err := eg.Wait(); err != nil {
return fmt.Errorf("got EOF. failed to wait for plugin: %w", err)
return fmt.Errorf("plugin write failed: %w", err)
}
return msg.SendAndClose(&pb.Write2_Response{})
}
close(resources)
if err := eg.Wait(); err != nil {
s.Logger.Error().Err(err).Msg("got error. failed to wait for plugin")
return fmt.Errorf("plugin write failed: %w", err)
}
return fmt.Errorf("failed to receive msg: %w", err)
}
var resource schema.DestinationResource
if err := json.Unmarshal(r.Resource, &resource); err != nil {
close(resources)
if err := eg.Wait(); err != nil {
s.Logger.Error().Err(err).Msg("failed to unmarshal resource. failed to wait for plugin")
// log the unmarshal error so we don't lose that information, but return the write error as that's the first one that occurred
s.Logger.Error().Err(err).Msg("failed to unmarshal resource")
return fmt.Errorf("plugin write failed: %w", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are losing the information from the original JSON unmarshal error here now - that's why the previous implementation only logged the Wait error and then returned the original JSON unmarshal error. Maybe we should keep it that way? I'm open to other options too, but we shouldn't drop that error without logging it at least

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure. I actually think we should return a list of errors, but that's a bigger change.
I think the Write error is the first one that occurred so it makes more sense to return it.
I'll add a log for the unmarshal error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#487 should allow us to report both

}
return status.Errorf(codes.InvalidArgument, "failed to unmarshal resource: %v", err)
}
Expand All @@ -113,7 +115,7 @@ func (s *DestinationServer) Write2(msg pb.Destination_Write2Server) error {
case <-ctx.Done():
close(resources)
if err := eg.Wait(); err != nil {
s.Logger.Error().Err(err).Msg("failed to wait")
return fmt.Errorf("plugin write failed: %w", err)
}
return ctx.Err()
Copy link
Copy Markdown
Member Author

@erezrokah erezrokah Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.Err() returns context canceled when the write fails, which is not the error we want

}
Expand Down