Skip to content

MOBILE-120: Limit errorDetails to 1000 characters in InappShowFailureManager#700

Merged
Vailence merged 3 commits intodevelopfrom
feature/MOBILE-120-errorDetails-max-1000
Apr 29, 2026
Merged

MOBILE-120: Limit errorDetails to 1000 characters in InappShowFailureManager#700
Vailence merged 3 commits intodevelopfrom
feature/MOBILE-120-errorDetails-max-1000

Conversation

@Vailence
Copy link
Copy Markdown
Collaborator

Ticket: https://tracker.yandex.ru/MOBILE-120

Summary

Ограничивает поле errorDetails в InAppShowFailure максимум 1000 символами перед отправкой на бэк, чтобы избежать раздувания payload-а при длинных сообщениях об ошибках.

Type of Change

  • Feature

Changes

  • Добавлена константа InappShowFailureManager.errorDetailsLimit = 1000
  • В createFailure(...) errorDetails обрезается через String(prefix(errorDetailsLimit)) — единая точка обрезки для всех путей создания failure
  • Добавлены 6 unit-тестов на границы лимита (ниже/равен/выше), nil, пустую строку и сценарий приоритетной замены failure с длинным errorDetails

Testing

  • Unit tests added/updated
  • Manual testing performed

@Vailence Vailence requested a review from justSmK April 28, 2026 07:57
Comment thread Mindbox/InAppMessages/InappShowFailureManager.swift Outdated
Comment thread Mindbox/InAppMessages/InappShowFailureManager.swift
@justSmK
Copy link
Copy Markdown
Collaborator

justSmK commented Apr 28, 2026

image

Здесь можешь сделать update with rebase. Я в develop фикс для fastlane залил

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 errorDetails to 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.

Comment thread Mindbox/InAppMessages/InappShowFailureManager.swift
@Vailence Vailence force-pushed the feature/MOBILE-120-errorDetails-max-1000 branch from 30f6f19 to 51b5e46 Compare April 29, 2026 08:38
Copilot AI review requested due to automatic review settings April 29, 2026 08:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.errorDetailsLimit and truncation of details before buffering failures.
  • Added String.truncated(toUTF8ByteLimit:) helper and corresponding unit tests.
  • Expanded InappShowFailureManager unit 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 > limit forces 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 to limit (or limit+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.

Comment on lines +19 to +21
/// Backend payload limit for errorDetails.
static let errorDetailsLimit = 1000

Comment thread Mindbox/InAppMessages/InappShowFailureManager.swift Outdated
Copilot AI review requested due to automatic review settings April 29, 2026 09:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.errorDetailsLimit and truncate details before 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

  • Character doesn’t expose an utf8 view; character.utf8.count is likely a compile error. To measure the UTF-8 bytes for a grapheme cluster, convert to String(character) (or compute via character.unicodeScalars) before counting bytes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +21
/// Backend payload limit for errorDetails.
static let errorDetailsLimit = 1000

@@ -2266,7 +2235,6 @@
children = (
0475E8755F63483597539A50 /* TrackVisitManagerTests.swift */,
);
Comment on lines +43 to +45
let truncatedDetails = details.map { original -> String in
let truncated = original.truncated(toUTF8ByteLimit: Self.errorDetailsLimit)
if truncated != original {
@Vailence Vailence requested a review from justSmK April 29, 2026 13:40
@justSmK justSmK force-pushed the feature/MOBILE-120-errorDetails-max-1000 branch from d9b0037 to f73cbf1 Compare April 29, 2026 14:45
@Vailence Vailence merged commit 14b73fc into develop Apr 29, 2026
4 checks passed
@Vailence Vailence deleted the feature/MOBILE-120-errorDetails-max-1000 branch April 29, 2026 15:08
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