Closed vkuptcov closed 3 months ago
Hi @vkuptcov
Nice catch! Thanks for the contribution!
Upon further review, I don't think the code in this PR will do anything, but it wouldn't hurt having it. Hopefully, that fixed your problem.
@dvonthenen bytesRead, err := r.Read(chunk)
might return nil
error, in that case when err.Error()
is called we have a panic.
The issue was introduced in this commit https://github.com/deepgram/deepgram-go-sdk/blob/1efb312b6b072c1c16962e0cc0dbb510d9c4677f/pkg/client/live/client.go#L355C4-L355C10
before the error was handled in a different way https://github.com/deepgram/deepgram-go-sdk/blob/a036640bcd2354c13eb60fb96d82eec27360fd5e/pkg/client/live/client.go#L278 so it didn't produced a panic.
In general, I would suggest to get rid of using direct errors comparison like here (err == io.EOF || err == io.ErrUnexpectedEOF)
and replace it with errors.Is
approach that is described here https://go.dev/wiki/ErrorValueFAQ
You are absolutely right. It will return nil
. It should return nil
most of the time. When I run without the added code, it drops through in the "default" which you don't really need since it's implied in the switch statement.
The reason why we are using the direct error comparison is because the behavior is different depending on the error. For io.EOF
and io.ErrUnexpectedEOF
, we want to log the behavior difference and exit gracefully (as you can see in the return nil
).
The behavior you are seeing versus what I am seeing appear to be vastly different. What version of go are you using?
I can run the example without any issues or segfaults.
$ go version
go version go1.22.1 linux/amd64
Will give this a try using the latest 1.22.
I dont have any problem running the example on 1.22.1
and 1.22.3
without the added code in this PR but I am also on darwin/arm64
. 🤔
In any case, the new code shouldn't hurt.
I'll create a simple project to illustrate the issue.
I'll create a simple project to illustrate the issue.
No need. I definitely understand, but drop it here if you wish.
Proposed changes
This PR fixes error handling inside
func (c *Client) Stream(r io.Reader) error
function. The current implementation tries to callerr.Error()
in the first switchcase strings.Contains(err.Error(), FatalReadSocketErr)
. It leads to a panic in case of handling successful results.Types of changes
What types of changes does your code introduce to the community Go SDK? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments