Skip to content

Commit d30b176

Browse files
committed
Fix precondition failure in addAttributes(_:range:updateLayout:)
Replace preconditionFailure with assertionFailure and return early when encountering an invalid range in addAttributes(_:range:updateLayout:). This avoids crashing in release builds if an invalid range is passed.
1 parent 556d708 commit d30b176

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/STTextViewAppKit/STTextView.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ import AVFoundation
869869
/// Add attribute. Need `needsViewportLayout = true` to reflect changes.
870870
private func addAttributes(_ attrs: [NSAttributedString.Key: Any], range: NSRange, updateLayout: Bool) {
871871
guard let textRange = NSTextRange(range, in: textContentManager) else {
872-
preconditionFailure("Invalid range \(range)")
872+
assertionFailure("Invalid range \(range)")
873+
return
873874
}
874875

875876
addAttributes(attrs, range: textRange, updateLayout: updateLayout)

0 commit comments

Comments
 (0)