Closed benoittgt closed 4 years ago
PR in draft mode. I will fix the CI.
The PR looks good for a review. :)
I am wondering what we want to manage here? Wrapping the error?
Can we consider the InvalidRangeError
and friends read errors which would make the parser stop when reading? I believe we can rescue those (using a regexp so that you don't need the class definition) and re-raise as InvalidRead
which is captured during parsing normally?
Sorry didn't cover all of your questions
Do we want to wrap ActiveStorage errors? Like ActiveStorage::FileNotFoundError?
I am inclined not to - it is not the responsibility of the library
Did I properly handle BlobIO#size and @pos.bytesize?
I doubt @pos
can have a bytesize. But blob sizes are always in bytes and all encodings are assumed to be binary, so what I see is perfect 👍
Different behavior with a io.read(NEGATIVE_INT). Local storage returns "", S3 returns all the file. I am wondering in which case we could have a negative n_bytes to read?
Only If we use a library which performs a read with negative bytes, and even then I would consider it a bug in that library. We can forbid it on the level of the IO constraint as I don't think it is a valid operation. For example a File
object (the "ur-IO") does this:
[1] pry(main)> f = File.open('ttt', 'wb')
=> #<File:ttt>
[2] pry(main)> f.read(-3)
ArgumentError: negative length -3 given
from (pry):2:in `read'
Looks great! What I have questions about is the use of min.io. Given that we use a published (and public) API in ActiveStorage which has defined semantics, do we really need to test with an S3-like service? We are pulling quite a dependency in (and need to integrate it and ensure it keeps working, and it apparently has Ruby version limitations). Are we certain what we are testing cannot be reliably tested with DiskService alone?
I thought about this a lot. I was a little bit worried to have s3 issues that were not detected by the test suite because we were only using disk storage service (range for example, remote server status, etc). At the same time having a local s3 storage with min.io add a lot of code and also a dependency that could reduce the speed of development and the cost of maintaining the gem. Also I think we should not test s3 or other remote services again. download_chunk
should be the only entry point, the details behind should not be tested by us.
Testing in a s3 scenario was interesting for development purpose but not sure it will serve that much expect as non-regression test.
It is up to you @julik :)
It is up to you @julik :)
Right - in that case let's ditch S3 and minio :-) S3 has errors on about 0.1% - 0.4% of requests, but if this needs to be tackled it will be the storage service module in ActiveStorage where it needs to happen.
Not sure I get what are "friends". Do you want to wrap at a different namespace level the errors for example /AWS::S3::Errors/
Ideally I thought we could somehow convert those errors into InvalidRead
so that if a parser reads too much - and causes an error - FormatParser could proceed to activate the next parser in the set. But I think we might postpone this for later, and for now if there is an ActiveStorage-related error we let it bubble up through FormatParser and to the caller. If the feature proves useful and used we will narrow down on better rescuing strategies later? 💡
Hello @julik
Thanks a lot for your very clear feedback and explanation. I am completely ok to let this error pop, and improve the error handling if necessary. 🙏🏼
I removed the two commits with error rescuing.
This is heavily inspired by the good job made on #126.
Few questions I have: 1) Do we want to wrap ActiveStorage errors? Like
ActiveStorage::FileNotFoundError
? 2) Did I properly handleBlobIO#size
and@pos.bytesize
? 3) Different behavior with aio.read(NEGATIVE_INT)
. Local storage returns""
, S3 returns all the file. I am wondering in which case we could have a negativen_bytes
to read? 4) Inspired by https://github.com/shrinerb/shrine/commit/8d92a9fc2ab6d742f1a022af2dc65fb11dbb0408, I choose Minio for S3 interaction. This add a lot of code but also simplify local development. https://shrinerb.com/docs/testing#minioAs mentioned in a previous comment by @julik
Is this you are speaking about ?
I am wondering what we want to manage here? Wrapping the error?
Close: #93