Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle client error after all data consumed in #copy_data for output #455

Merged
merged 2 commits into from May 18, 2022

Conversation

stevewoodcock
Copy link
Contributor

During #copy_data for output, if an exception is raised after consuming all the
data from get_copy_data, then the subsequent cleanup triggers a "no COPY in
progress" error when it tries to call get_copy_data again, which causes the
original exception to be lost.

Fix by ignoring PG::Error during get_copy_data cleanup.

During #copy_data for output, if an exception is raised after consuming all the
data from get_copy_data, then the subsequent cleanup triggers a "no COPY in
progress" error when it tries to call get_copy_data again, which causes the
original exception to be lost.

Fix by ignoring PG::Error during get_copy_data cleanup.
Previously this test failed on TruffleRuby because the finally raised exception
was a RuntimeError with no message. It looks like TruffleRuby doesn't raise the
originally caught exception in this case, ie if there is an intermediate
exception between the original one and the raise with no args. Fix by explicitly
raising the originally caught exception.
@larskanis
Copy link
Collaborator

Thank you for fixing another corner case of the copy function!

copy_data is a function, that has some funny history on my end. At first I stumbled upon various issues with the COPY function and the related client side implementation on my own. Then I noticed that all other implementations in the company and the internet were wrong in some aspect. So I tried to teach anyone else how to implement it right. Then I wondered if there couldn't be a builtin method in ruby-pg that handles the corner cases right. Unfortunately while testing copy_data in 2013, I noticed that all my former implementations were wrong in some way as well. Since then I'm glad, that there is a proper helper in ruby-pg and I encourage everyone to use it. Now - almost a decade later - you found another corner case. Very good catch!

@larskanis larskanis merged commit a40dd7b into ged:master May 18, 2022
@stevewoodcock
Copy link
Contributor Author

You are most welcome, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants