Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the error is a
resource.TimeoutError
and we hit this condition, its important that we reset the error object so the later error checking logic is not triggered. Otherwise as written this will work like the following:resource.Retry
sets top levelerr
toresource.TimeoutError
isResourceTimeoutError(err)
conditional runsCreateListener
again (great!)CreateListener
returns an error, it returns the errorCreateListener
doesn't return an error, theisResourceTimeoutError()
conditional exits, but the below error check (if err != nil
) will still have the originalresource.TimeoutError
error, so it will still return an errorThe trick here is using a direct
=
assignment in Go instead of:=
This allows us to simplify this logic like the following:
You'll now get the outcome you're expecting both ways when
resource.Retry
has a timeout error:resource.Retry
sets top levelerr
toresource.TimeoutError
isResourceTimeoutError(err)
conditional runsCreateListener
again (great!)CreateListener
returns an error, it resets the top level error object and the below error check (if err != nil
) will return that errorCreateListener
doesn't return an error, the top level error object is reset tonil
and the below error check (if err != nil
) will not trigger so the resource will continue on its merry way on the happy pathHope this helps!