fix(destinations): Propagate write errors#461
fix(destinations): Propagate write errors#461erezrokah wants to merge 2 commits intocloudquery:mainfrom
Conversation
| s.Logger.Error().Err(err).Msg("failed to wait") | ||
| return fmt.Errorf("plugin write failed: %w", err) | ||
| } | ||
| return ctx.Err() |
There was a problem hiding this comment.
ctx.Err() returns context canceled when the write fails, which is not the error we want
⏱️ Benchmark resultsComparing with 3fecc61
|
| close(resources) | ||
| if err := eg.Wait(); err != nil { | ||
| s.Logger.Error().Err(err).Msg("failed to unmarshal resource. failed to wait for plugin") | ||
| return fmt.Errorf("plugin write failed: %w", err) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Related to cloudquery/cloudquery#5152. This fixes an issue when if the channel gets closed (for example there's an error during write), we report the `EOF` error instead of the original error. Scenario from the issue: 1. Users runs `sync --no-migrate` on a non initialized database 2. [`Write`](https://github.com/cloudquery/plugin-sdk/blob/ab7ca972e0b187a7dfb66132a03f07479cd29bb7/internal/servers/destinations.go#L84) fails on the first table write, returning an error from this function: https://github.com/cloudquery/plugin-sdk/blob/ab7ca972e0b187a7dfb66132a03f07479cd29bb7/internal/servers/destinations.go#L65, causing the channel to close 3. The next iteration of `for resource := range resources` starts, receiving an `EOF` error since the channel is closed, and `EOF` error is reported. > This is only a patch. I think we should separate application level errors (e.g. write) from protocol/communication level errors. I'll open a separate issue for that **Also, [another related fix coming](#461 ---
|
Closed by #529 |
Summary
Related to cloudquery/cloudquery#5152 and #460
The error returned from the error group
Wait()function is the error reported by the Go routine, not the error of theWait()functionUse the following steps to ensure your PR is ready to be reviewed
go fmtto format your code 🖊golangci-lint run🚨 (install golangci-lint here)