Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Crashlytics/Crashlytics/FIRCrashlytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "Crashlytics/Crashlytics/Helpers/FIRCLSUtility.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSExecutionIdentifierModel.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSFileManager.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSNonFatalError.h"
#import "Crashlytics/Crashlytics/Models/FIRCLSSettings.h"
#import "Crashlytics/Crashlytics/Settings/Models/FIRCLSApplicationIdentifierModel.h"

Expand Down Expand Up @@ -431,16 +432,13 @@ - (void)recordError:(NSError *)error userInfo:(NSDictionary<NSString *, id> *)us

NSString *rolloutsInfoJSON = [_remoteConfigManager getRolloutAssignmentsEncodedJsonString];
Comment thread
mghaznav marked this conversation as resolved.

// Capture the stack and time before the async queue.
// Capturing inside the callback, results in the promise
// thread being recorded rather than the caller thread.
NSArray *addresses = [NSThread callStackReturnAddresses];
uint64_t timestamp = time(NULL);
FIRCLSNonFatalError *nonFatalError = [[FIRCLSNonFatalError alloc] initWithError:error
userInfo:userInfo
rolloutsInfoJSON:rolloutsInfoJSON];

[self waitForContextInit:@"recordError"
callback:^{
FIRCLSUserLoggingRecordError(error, userInfo, rolloutsInfoJSON, addresses,
timestamp);
[nonFatalError recordError];
}];
}

Expand Down
56 changes: 56 additions & 0 deletions Crashlytics/Crashlytics/Models/FIRCLSNonFatalError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
* An internal model representing a logged non-fatal error.
* This class synchronously captures the thread state and timestamp upon
* initialization to safely preserve the execution context.
*/
@interface FIRCLSNonFatalError : NSObject

@property(nonatomic, strong, readonly) NSError *error;
@property(nonatomic, copy, readonly, nullable) NSDictionary<NSString *, id> *userInfo;
@property(nonatomic, copy, readonly, nullable) NSString *rolloutsInfoJSON;
@property(nonatomic, copy, readonly) NSArray<NSNumber *> *stackTrace;
Comment thread
mghaznav marked this conversation as resolved.
@property(nonatomic, assign, readonly) uint64_t timestamp;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

/**
* Initializes a non-fatal error, recording the stack trace at initialization.
* Fails to initialize if error is nil.
*
* @param error The NSError being logged. If nil, initialization fails.
* @param userInfo Optional dictionary of custom key-value pairs.
* @param rolloutsInfoJSON Optional JSON string containing active feature rollouts.
*/
- (nullable instancetype)initWithError:(NSError *)error
userInfo:(nullable NSDictionary<NSString *, id> *)userInfo
rolloutsInfoJSON:(nullable NSString *)rolloutsInfoJSON
NS_DESIGNATED_INITIALIZER;

/**
* Records the error to disk. No-op if intialization failed.
* The action to record to disk is executed on the thread this method is called on.
*/
- (void)recordError;

@end

NS_ASSUME_NONNULL_END
44 changes: 44 additions & 0 deletions Crashlytics/Crashlytics/Models/FIRCLSNonFatalError.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import "Crashlytics/Crashlytics/Models/FIRCLSNonFatalError.h"
#include "Crashlytics/Crashlytics/Components/FIRCLSUserLogging.h"

@implementation FIRCLSNonFatalError

- (instancetype)initWithError:(NSError *)error
userInfo:(NSDictionary<NSString *, id> *)userInfo
rolloutsInfoJSON:(NSString *)rolloutsInfoJSON {
if (!error) {
return nil;
}

self = [super init];
if (self) {
_error = error;
_userInfo = [userInfo copy];
_rolloutsInfoJSON = [rolloutsInfoJSON copy];
// Take a snapshot of the thread at initialization.
_stackTrace = [NSThread callStackReturnAddresses];
_timestamp = time(NULL);
}
return self;
}

- (void)recordError {
FIRCLSUserLoggingRecordError(self.error, self.userInfo, self.rolloutsInfoJSON, self.stackTrace,
self.timestamp);
}

@end
Loading