Skip to content

Make ObjectiveCError type Sendable without warnings#73

Merged
dfed merged 7 commits into
mainfrom
dfed--warning-xcode-14
Nov 19, 2022
Merged

Make ObjectiveCError type Sendable without warnings#73
dfed merged 7 commits into
mainfrom
dfed--warning-xcode-14

Conversation

@dfed

@dfed dfed commented Nov 5, 2022

Copy link
Copy Markdown
Owner

Error inherits from Sendable, but NSException does not conform to Sendable (probably due to the raise() method?). In order to remove a warning that ObjectiveCError does not actually conform to Sendable on Xcode 14+, I made ObjectiveCError include the exception name and the reason.

Since ObjectiveCError is not public, this is not a breaking change.

@dfed dfed requested review from bachand and fdiaz November 5, 2022 00:25
@codecov

codecov Bot commented Nov 5, 2022

Copy link
Copy Markdown

Codecov Report

Merging #73 (d051e71) into main (61f099f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #73   +/-   ##
=======================================
  Coverage   98.92%   98.92%           
=======================================
  Files          13       13           
  Lines         556      560    +4     
=======================================
+ Hits          550      554    +4     
  Misses          6        6           
Impacted Files Coverage Δ
Sources/CacheAdvance/CacheReader.swift 93.67% <100.00%> (+0.16%) ⬆️
Sources/CacheAdvance/ObjectiveC.swift 100.00% <100.00%> (ø)

Comment thread Sources/CacheAdvance/CacheReader.swift Outdated
}
}
if let endOffset = endOffset, offsetInFile != endOffset {
if let endOffset = endOffset, offsetInFile < endOffset {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated to this PR. It addresses this comment on #72.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check for the > case a few lines above:

} else if offsetInFile > endOffset {
throw CacheAdvanceError.fileCorrupted
}

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @jianjunwoo has been doing great thinking here and authored this code I'll also tag him here for visibility 👍

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

@jianjunwoo jianjunwoo Nov 19, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dfed

dfed commented Nov 10, 2022

Copy link
Copy Markdown
Owner Author

@bachand @fdiaz once this PR is approved and merged I'll release the next version bump on Cocoapods.

Comment thread Sources/CacheAdvance/ObjectiveC.swift
Comment thread Sources/CacheAdvance/CacheReader.swift Outdated
}
}
if let endOffset = endOffset, offsetInFile != endOffset {
if let endOffset = endOffset, offsetInFile < endOffset {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread Sources/CacheAdvance/CacheReader.swift Outdated
Comment thread Sources/CacheAdvance/CacheReader.swift Outdated
}
}
if let endOffset = endOffset, offsetInFile != endOffset {
if let endOffset = endOffset, offsetInFile < endOffset {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Comment thread Sources/CacheAdvance/CacheReader.swift Outdated
}
}
if let endOffset = endOffset, offsetInFile != endOffset {
if let endOffset = endOffset, offsetInFile < endOffset {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @jianjunwoo has been doing great thinking here and authored this code I'll also tag him here for visibility 👍

@dfed dfed merged commit 3461cbb into main Nov 19, 2022
@dfed dfed deleted the dfed--warning-xcode-14 branch November 19, 2022 03:17
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.

3 participants