Conversation
There was a problem hiding this comment.
Pull request overview
Implements a safeguard to cap InAppShowFailure.errorDetails at 1000 characters before enqueuing/sending the Inapp.ShowFailure event, preventing oversized payloads from long error messages.
Changes:
- Added
InappShowFailureManager.errorDetailsLimit = 1000. - Truncated
errorDetailsto the limit in the centralized failure construction path (makeFailure). - Added unit tests covering below/at/above-limit,
nil, empty string, and priority replacement behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
Mindbox/InAppMessages/InappShowFailureManager.swift |
Adds the errorDetails length cap when constructing InAppShowFailure instances. |
MindboxTests/InApp/Tests/InappShowFailureManagerTests.swift |
Adds unit tests validating truncation behavior and edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
30f6f19 to
51b5e46
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a size cap for InAppShowFailure.errorDetails to reduce the risk of oversized in-app failure payloads being enqueued/sent to the backend.
Changes:
- Added
InappShowFailureManager.errorDetailsLimitand truncation ofdetailsbefore buffering failures. - Added
String.truncated(toUTF8ByteLimit:)helper and corresponding unit tests. - Expanded
InappShowFailureManagerunit coverage for truncation boundaries and replacement behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Mindbox/InAppMessages/InappShowFailureManager.swift | Adds an errorDetails size limit and truncates details before storing failures (includes debug logging when truncation occurs). |
| Mindbox/Extensions/String+Extensions.swift | Adds a UTF-8 byte–based truncation helper that avoids splitting grapheme clusters. |
| MindboxTests/InApp/Tests/InappShowFailureManagerTests.swift | Adds tests covering below/at/above limit, nil/empty, multibyte/emoji behavior, and priority replacement truncation. |
| MindboxTests/Extensions/StringExtensionsTests.swift | Adds edge-case tests for zero/negative truncation limits. |
| Mindbox.xcodeproj/project.pbxproj | Project file adjustments related to String+Extensions.swift grouping/references. |
Comments suppressed due to low confidence (1)
Mindbox/Extensions/String+Extensions.swift:58
guard utf8.count > limitforces a full UTF-8 byte count of the entire string (O(n)) before truncating, which can be expensive for very large inputs—the main case this helper is meant to handle. Consider rewriting to scan only up tolimit(orlimit+1) bytes/characters and early-exit without ever counting the full string length.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Backend payload limit for errorDetails. | ||
| static let errorDetailsLimit = 1000 | ||
|
|
There was a problem hiding this comment.
Pull request overview
Implements truncation of InAppShowFailure.errorDetails before enqueueing/sending failures to keep backend payload size under control, and adds unit coverage for boundary cases (including multibyte strings).
Changes:
- Added
InappShowFailureManager.errorDetailsLimitand truncatedetailsbefore buffering/sending failures. - Introduced
String.truncated(toUTF8ByteLimit:)helper for UTF-8 byte-based truncation without splitting grapheme clusters. - Added/expanded unit tests for truncation limits and edge cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Mindbox/InAppMessages/InappShowFailureManager.swift | Truncates errorDetails (currently by UTF-8 bytes) before storing/sending. |
| Mindbox/Extensions/String+Extensions.swift | Adds UTF-8 byte limit string truncation helper. |
| MindboxTests/InApp/Tests/InappShowFailureManagerTests.swift | Adds tests for below/at/above limit, nil/empty, multibyte and replacement scenarios. |
| MindboxTests/Extensions/StringExtensionsTests.swift | Adds tests for zero/negative UTF-8 byte limits. |
| Mindbox.xcodeproj/project.pbxproj | Project file updates, including moving String+Extensions.swift reference and other group formatting churn. |
Comments suppressed due to low confidence (1)
Mindbox/Extensions/String+Extensions.swift:66
Characterdoesn’t expose anutf8view;character.utf8.countis likely a compile error. To measure the UTF-8 bytes for a grapheme cluster, convert toString(character)(or compute viacharacter.unicodeScalars) before counting bytes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Backend payload limit for errorDetails. | ||
| static let errorDetailsLimit = 1000 | ||
|
|
| @@ -2266,7 +2235,6 @@ | |||
| children = ( | |||
| 0475E8755F63483597539A50 /* TrackVisitManagerTests.swift */, | |||
| ); | |||
| let truncatedDetails = details.map { original -> String in | ||
| let truncated = original.truncated(toUTF8ByteLimit: Self.errorDetailsLimit) | ||
| if truncated != original { |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
d9b0037 to
f73cbf1
Compare

Ticket: https://tracker.yandex.ru/MOBILE-120
Summary
Ограничивает поле
errorDetailsвInAppShowFailureмаксимум 1000 символами перед отправкой на бэк, чтобы избежать раздувания payload-а при длинных сообщениях об ошибках.Type of Change
Changes
InappShowFailureManager.errorDetailsLimit = 1000createFailure(...)errorDetailsобрезается черезString(prefix(errorDetailsLimit))— единая точка обрезки для всех путей создания failureerrorDetailsTesting