From 758ceb9b6207e1c439e4fd7087a3d7f284328f48 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 20 Feb 2024 08:40:05 +0100 Subject: [PATCH] test: Fix failing UIViewController tests The with GH-3529 added test method writeProfileFile crashed when a profile file already existed. Now, the writeProfileFile method exists and prints a debug message when a profiling file already exists and logs an error when it can't write the profile. --- Sources/Sentry/SentryProfiler.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index b98753280ec..5875a7d3cec 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -469,15 +469,19 @@ + (nullable SentryEnvelopeItem *)createEnvelopeItemForProfilePayload: } if ([fm fileExistsAtPath:pathToWrite]) { - SENTRY_LOG_DEBUG(@"Already a%@ profile file present; make sure to remove them right after " + SENTRY_LOG_DEBUG(@"Already a %@ profile file present; make sure to remove them right after " @"using them, and that tests clean state in between so there isn't " @"leftover config producing one when it isn't expected.", isTracingAppLaunch ? @" launch" : @""); + return; } SENTRY_LOG_DEBUG(@"Writing%@ profile to file.", isTracingAppLaunch ? @" launch" : @""); - SENTRY_CASSERT( - [data writeToFile:pathToWrite atomically:YES], @"Failed to write profile to test file"); + + NSError *error; + if (![data writeToFile:pathToWrite options:NSDataWritingAtomic error:&error]) { + SENTRY_LOG_ERROR(@"Failed to write data to path %@: %@", pathToWrite, error); + } } # endif // defined(TEST) || defined(TESTCI) || defined(DEBUG)