openzim / python-libzim

Libzim binding for Python: read/write ZIM files in Python
https://pypi.org/project/libzim/
GNU General Public License v3.0
62 stars 20 forks source link

Forward exceptions from Article's virtual methods #55

Closed rgaudin closed 4 years ago

rgaudin commented 4 years ago

This addresses (badly I presume) the problem that users need to stop on user-code error inside Article's virtual method. It's essential otherwise they'll endup with garbaged ZIM files. This first commit (8ed926d) achieves that but there is probably a be a better way to do it.

--

Another related commit regards the next step in this process, being able to stop the creation process when an error occurs. The only workaround I found was to prevent calling finalize() (node-libzim and zimwritefs exits before calling it for instance). As we call close() and thus finalize() on __exit__ and __del__, for convenience, we have to bypass this.

It works fine in scrapers but not on the tests as the reader's tests trigger a manual garbage collection which the libzim is not happy with, as finalize() was never called…

To overcome that yet still test this important capability, I'm instanciating a new VM in the test.

@mgautierfr, please consider it a POC to start the discussion on this. We can surely opt this test out for now . Exception stuff is mandatory though.

rgaudin commented 4 years ago

Superseeded by #56.