Skip to content

Commit 831dd5e

Browse files
authored
fix(database): Prevent exception loop LP-8132 (#113)
1 parent bcb27cc commit 831dd5e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Leanplum-SDK/Classes/Constants.m

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,17 @@ void leanplumInternalError(NSException *e)
315315
int userCodeBlocks = [[[[NSThread currentThread] threadDictionary]
316316
objectForKey:LP_USER_CODE_BLOCKS] intValue];
317317
if (userCodeBlocks <= 0) {
318-
[[LeanplumRequest post:LP_METHOD_LOG
319-
params:@{
320-
LP_PARAM_TYPE: LP_VALUE_SDK_ERROR,
321-
LP_PARAM_MESSAGE: [e description],
322-
@"stackTrace": [[e callStackSymbols] description] ?: @"",
323-
LP_PARAM_VERSION_NAME: versionName
324-
}] send];
318+
@try {
319+
[[LeanplumRequest post:LP_METHOD_LOG
320+
params:@{
321+
LP_PARAM_TYPE: LP_VALUE_SDK_ERROR,
322+
LP_PARAM_MESSAGE: [e description],
323+
@"stackTrace": [[e callStackSymbols] description] ?: @"",
324+
LP_PARAM_VERSION_NAME: versionName
325+
}] send];
326+
} @catch (NSException *e) {
327+
// This empty try/catch is needed to prevent crash <-> loop.
328+
}
325329
NSLog(@"Leanplum: INTERNAL ERROR: %@\n%@", e, [e callStackSymbols]);
326330
} else {
327331
NSLog(@"Leanplum: Caught exception in callback code: %@\n%@", e, [e callStackSymbols]);

Leanplum-SDK/Classes/LPDatabase.m

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,15 @@ - (void)runQuery:(NSString *)query bindObjects:(NSArray *)objectsToBind
160160
}
161161

162162
@synchronized (self) {
163-
sqlite3_stmt *statement = [self sqliteStatementFromQuery:query bindObjects:objectsToBind];
164-
if (!statement) {
165-
return;
166-
}
167-
168-
int result = sqlite3_step(statement);
169-
if (result != SQLITE_DONE) {
170-
[self handleSQLiteError:@"SQLite fail to run query" errorResult:result query:query];
163+
@try {
164+
sqlite3_stmt *statement = [self sqliteStatementFromQuery:query bindObjects:objectsToBind];
165+
if (!statement) {
166+
return;
167+
}
168+
} @catch (NSException *e) {
169+
LPLog(LPError, @"SQLite operation failed.");
170+
// TODO: Make sure to catch this when new logging is in place,
171171
}
172-
willSendErrorLog = NO;
173-
sqlite3_finalize(statement);
174172
}
175173
}
176174

0 commit comments

Comments
 (0)