Make ObjectiveCError type Sendable without warnings#73
Conversation
Codecov Report
@@ Coverage Diff @@
## main #73 +/- ##
=======================================
Coverage 98.92% 98.92%
=======================================
Files 13 13
Lines 556 560 +4
=======================================
+ Hits 550 554 +4
Misses 6 6
|
| } | ||
| } | ||
| if let endOffset = endOffset, offsetInFile != endOffset { | ||
| if let endOffset = endOffset, offsetInFile < endOffset { |
There was a problem hiding this comment.
This change is unrelated to this PR. It addresses this comment on #72.
There was a problem hiding this comment.
To make sure I follow... we'd end up throwing an error from this section of the code if the end offset was past EOF?
There was a problem hiding this comment.
Do you think we're losing any safety here by changing to <? I was imagining we'd add a comment to state our intention but leave the check the way it was.
There was a problem hiding this comment.
I can't imagine how we could end up with the > here but if we did it seems like that would mean we also have a corrupted file.
There was a problem hiding this comment.
We check for the > case a few lines above:
CacheAdvance/Sources/CacheAdvance/CacheReader.swift
Lines 56 to 58 in 61f099f
We aren't losing safety today by making this change, and with our current unit tests I don't believe we are losing future safety. Though if someone were to change the unit tests and modify this code we could end up with a future issue, but that doesn't seem terribly likely.
That said, I should absolutely add a comment.
There was a problem hiding this comment.
@dfed the concern I had was that if there was a bug in nextEncodedMessage() where we could end up in a situation (in theory) where we got to L61 and offsetInFile > endOffset. This could occur if the file were corrupted AND nextEncodedMessage() returned nil even though it advanced the reader.
Where I personally netted out was that checking offsetInFile != endOffset wasn't wrong but resulted in it being difficult for the reader to follow why the check existed. And I felt like that difficulty was resolved by the comment.
I'm open to the idea that this line of thinking is being too cautious though. I wanted to take a moment to voice my thought though I'm also supportive of merging this PR as-is.
There was a problem hiding this comment.
Since @jianjunwoo has been doing great thinking here and authored this code I'll also tag him here for visibility 👍
There was a problem hiding this comment.
the concern I had was that if there was a bug in
nextEncodedMessage()where we could end up in a situation (in theory) where we got to L61 andoffsetInFile > endOffset. This could occur if the file were corrupted ANDnextEncodedMessage()returnednileven though it advanced the reader.
This should not be possible, since the only way we return nil from nextEncodedMessage() is if we get an empty read (which would not advance the reader). That said, that's true today and may not be true forever.
I'll update this code + comment to be a bit more clear, then merge.
There was a problem hiding this comment.
"That said, that's true today and may not be true forever."
This is true : D
Overall, it looks fine in either way for me. There are unit tests to cover these cases I think. We've got noticed when it is not true.
On the other side, when the end offset is larger than the EOF, it could be a warning instead of an error to identify the incorrect endOffset. In this case, the messages are still valid. Currently, we treat this case in a strict way.
There was a problem hiding this comment.
On the other side, when the end offset is larger than the EOF, it could be a warning instead of an error to identify the incorrect endOffset. In this case, the messages are still valid. Currently, we treat this case in a strict way.
You're right! Prior to #66 we wouldn't have caught this case either. Though because of the == check we have, the only way to hit the offsetInFile > endOffset case is for something to have gone horribly wrong (like, more than just an untimely crash), so I think it's valid that we consider files in this state corrupted.
| } | ||
| } | ||
| if let endOffset = endOffset, offsetInFile != endOffset { | ||
| if let endOffset = endOffset, offsetInFile < endOffset { |
There was a problem hiding this comment.
To make sure I follow... we'd end up throwing an error from this section of the code if the end offset was past EOF?
| } | ||
| } | ||
| if let endOffset = endOffset, offsetInFile != endOffset { | ||
| if let endOffset = endOffset, offsetInFile < endOffset { |
There was a problem hiding this comment.
@dfed the concern I had was that if there was a bug in nextEncodedMessage() where we could end up in a situation (in theory) where we got to L61 and offsetInFile > endOffset. This could occur if the file were corrupted AND nextEncodedMessage() returned nil even though it advanced the reader.
Where I personally netted out was that checking offsetInFile != endOffset wasn't wrong but resulted in it being difficult for the reader to follow why the check existed. And I felt like that difficulty was resolved by the comment.
I'm open to the idea that this line of thinking is being too cautious though. I wanted to take a moment to voice my thought though I'm also supportive of merging this PR as-is.
| } | ||
| } | ||
| if let endOffset = endOffset, offsetInFile != endOffset { | ||
| if let endOffset = endOffset, offsetInFile < endOffset { |
There was a problem hiding this comment.
Since @jianjunwoo has been doing great thinking here and authored this code I'll also tag him here for visibility 👍
Errorinherits fromSendable, butNSExceptiondoes not conform toSendable(probably due to theraise()method?). In order to remove a warning thatObjectiveCErrordoes not actually conform toSendableon Xcode 14+, I madeObjectiveCErrorinclude the exception name and the reason.Since
ObjectiveCErroris notpublic, this is not a breaking change.