-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Return nil on applying() failure instead of crashing #26575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci Please test |
target.append(contentsOf: source[start..<index]) | ||
} | ||
|
||
difference._fastEnumeratedApply { change in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hunk is all whitespace changes with the exception of the addition of a do { … } catch { … }
block and associated sprinklings of try
.
let start = index | ||
source.formIndex(&index, offsetBy: count) | ||
if !source.formIndex(&index, offsetBy: count, limitedBy: source.endIndex) { | ||
throw _ApplicationError.failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These throws may throw off people who break on all throws. We can fix this later if it proves annoying.
@swift-ci test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci test |
The application of a diff onto an invalid base state is supposed to cause
nil
to be returned fromapplying()
, but instead it just crashes with an index out of bounds error.Oops.
Generally speaking maintaining consistent diff and base states is the programmer's responsibility, but not crashing on invalid application is necessary for diffs to be useful as a boundary type for passing between modules so someone else's bug doesn't turn into anyone else's crash.
This PR includes exhaustive coverage of the boundary between application success and failure as well as fixes for the failing tests, including the test from the original report.
Resolves <rdar://problem/53663769>