ruby-docx / docx

a ruby library/gem for interacting with .docx files
MIT License
431 stars 170 forks source link

Only close zip file if set #115

Closed bmulholland closed 1 year ago

bmulholland commented 3 years ago

When an invalid file is passed in and the Zip library throws an error, @zip is not set. Then the ensure runs and tries to close the zip var, which is nil. This raises a new error that covers up the actual error, making the issue harder to investigate. By only closing the zip file if it was actually opened, the original error is raised for invalid docx files.

bmulholland commented 3 years ago

This will help with issues like https://github.com/ruby-docx/docx/issues/100

bmulholland commented 3 years ago

Done and done :)

panozzaj commented 2 years ago

Thanks @bmulholland, this looks like a good change. I ran into this error when using this library for the first time when I didn't have my path correct. So I think this PR would result in a clearer error message.

bmulholland commented 1 year ago

@satoryu Would love to get this into the repo so we can stop maintaining our custom fork. If I resolve the conflicts now, would you merge it?

satoryu commented 1 year ago

@bmulholland yes!

bmulholland commented 1 year ago

Oh, well, looks like another, more recent PR was merged that did the same thing...