Skip to content

Commit

Permalink
Merge pull request #181 from WideSpectrumComputing/GH180
Browse files Browse the repository at this point in the history
Resolve GH180, GH176 and GH166
  • Loading branch information
akornich authored May 26, 2022
2 parents 41d8daa + 8190d02 commit 8ab423b
Show file tree
Hide file tree
Showing 35 changed files with 344 additions and 157 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co
### 2.3.0

- feat: Detection of possible Out-of-Memory issues
- fix: resolve #166 - v2.2.4 spams to log with NSLog on iOS
- fix: resolve #176 - Rollbar crashes when device runs out of memory
- fix: resolve #180 - SonarCloud: address current reliability issues

### 2.2.4

Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let package = Package(
name: "RollbarSDK",
platforms: [
// Oldest targeted platform versions that are supported by this product.
.macOS(.v10_11),
.iOS(.v9),
.tvOS(.v11),
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v7),
],
products: [
Expand Down
8 changes: 4 additions & 4 deletions RollbarAUL.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Pod::Spec.new do |s|
# s.resources = "Resources/*.png"

# When using multiple platforms:
s.osx.deployment_target = "10.11"
# s.ios.deployment_target = "9.0"
# s.tvos.deployment_target = "11.0"
# s.watchos.deployment_target = "4.0"
s.osx.deployment_target = "10.15"
# s.ios.deployment_target = "13.0"
# s.tvos.deployment_target = "13.0"
# s.watchos.deployment_target = "7.0"
# Any platform, if omitted:
# s.platform = :ios
# s.platform = :ios, "5.0"
Expand Down
4 changes: 2 additions & 2 deletions RollbarAUL/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ let package = Package(
platforms: [
// Oldest targeted platform versions that are supported by this product.
.macOS(.v10_15),
.iOS(.v9),
.tvOS(.v11),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v7),
],
products: [
Expand Down
8 changes: 4 additions & 4 deletions RollbarCocoaLumberjack.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Pod::Spec.new do |s|
# s.resources = "Resources/*.png"

# When using multiple platforms:
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.11"
s.tvos.deployment_target = "11.0"
s.watchos.deployment_target = "4.0"
s.osx.deployment_target = "10.15"
s.ios.deployment_target = "13.0"
s.tvos.deployment_target = "13.0"
s.watchos.deployment_target = "7.0"
# Any platform, if omitted:
# s.platform = :ios
# s.platform = :ios, "5.0"
Expand Down
6 changes: 3 additions & 3 deletions RollbarCocoaLumberjack/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let package = Package(
name: "RollbarCocoaLumberjack",
platforms: [
// Oldest targeted platform versions that are supported by this product.
.macOS(.v10_11),
.iOS(.v9),
.tvOS(.v11),
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v7),
],
products: [
Expand Down
2 changes: 1 addition & 1 deletion RollbarCommon.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Pod::Spec.new do |s|
# s.resources = "Resources/*.png"

# When using multiple platforms:
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.11"
s.ios.deployment_target = "9.0"
s.tvos.deployment_target = "11.0"
s.watchos.deployment_target = "4.0"
# Any platform, if omitted:
Expand Down
8 changes: 4 additions & 4 deletions RollbarCommon/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ let package = Package(
name: "RollbarCommon",
platforms: [
// Oldest targeted platform versions that are supported by this product.
.macOS(.v10_10),
.iOS(.v9),
.tvOS(.v11),
.watchOS(.v4),
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v7),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
24 changes: 17 additions & 7 deletions RollbarCommon/Sources/RollbarCommon/DTOs/RollbarDTO+Protected.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,29 @@ - (NSNumber *)safelyGetNumberByKey:(NSString *)key {

#pragma mark - data setters by key

- (void)setDictionary:(NSDictionary *)data forKey:(NSString *)key {
[self setData:data.mutableCopy byKey:key];
- (void)setDictionary:(nullable NSDictionary *)data forKey:(NSString *)key {

[self setData:data ? data.mutableCopy : data
byKey:key
];
}

- (void)setArray:(NSArray *)data forKey:(NSString *)key {
[self setData:data.mutableCopy byKey:key];
- (void)setArray:(nullable NSArray *)data forKey:(NSString *)key {

[self setData:data ? data.mutableCopy : data
byKey:key
];
}

- (void)setString:(NSString *)data forKey:(NSString *)key {
[self setData:data.mutableCopy byKey:key];
- (void)setString:(nullable NSString *)data forKey:(NSString *)key {

[self setData:data ? data.mutableCopy : data
byKey:key
];
}

- (void)setNumber:(NSNumber *)data forKey:(NSString *)key {
- (void)setNumber:(nullable NSNumber *)data forKey:(NSString *)key {

[self setData:data byKey:key];
}

Expand Down
23 changes: 19 additions & 4 deletions RollbarCommon/Sources/RollbarCommon/DTOs/RollbarDTO.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ @implementation RollbarDTO {

#pragma mark - JSON processing routines

+ (BOOL)isTransferableObject:(id)obj {
BOOL result = [NSJSONSerialization isValidJSONObject:obj];
return result;
+ (BOOL)isTransferableObject:(nullable id)obj {

if (obj) {

BOOL result = [NSJSONSerialization isValidJSONObject:obj];
return result;
}
else {

return NO;
}
}

+ (BOOL)isTransferableDataValue:(id)obj {

if (obj == [NSNull null]
|| [obj isKindOfClass:[NSString class]]
|| [obj isKindOfClass:[NSNumber class]]
Expand Down Expand Up @@ -338,24 +347,30 @@ - (instancetype)initWithDictionary:(nullable NSDictionary<NSString *, id> *)data
self->_dataArray = nil;
self->_dataDictionary = nil;

if (!data) {
if (nil == data) {

data = [NSMutableDictionary dictionary];
}

if (![RollbarDTO isTransferableObject:data]) {

return self;
}

if ([data isKindOfClass:[NSMutableDictionary class]]) {

self->_data = (NSMutableDictionary *) data;
}
else {

self->_data = data.mutableCopy;
}
self->_dataArray = nil;
self->_dataDictionary = (NSMutableDictionary<NSString *, id> *) self->_data;
for (NSString *key in self->_dataDictionary.allKeys) {

if (self->_dataDictionary[key] == (id)[NSNull null]) {

[self->_dataDictionary removeObjectForKey:key];
}
}
Expand Down
92 changes: 92 additions & 0 deletions RollbarCommon/Sources/RollbarCommon/RollbarFileWriter.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#import "RollbarFileWriter.h"
#import "RollbarSdkLog.h"

@implementation RollbarFileWriter

+ (BOOL)ensureFileExists: (nullable NSString *)fileFullPath {

if (!(fileFullPath && (fileFullPath.length > 0))) {

RollbarSdkLog(@"Can't ensure existance of this file: %@!", fileFullPath);
NO;
}

// make sure the file exists:
if (![[NSFileManager defaultManager] fileExistsAtPath:fileFullPath]) {

if (![[NSFileManager defaultManager] createFileAtPath:fileFullPath
contents:nil
attributes:nil]) {
RollbarSdkLog(@" Error while creating file: %@", fileFullPath);
return NO;
}
}

return YES;
}

+ (void)appendData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath {

if (!(data && fileFullPath && (fileFullPath.length > 0))) {

RollbarSdkLog(@"Can't append data: %@ to file: %@!", data, fileFullPath);
return;
}

// append-save the data into the file (assuming it exists):

NSError *error;

NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:fileFullPath];
if (!fileHandle) {

RollbarSdkLog(@" Error while acquiring file handle for: %@", fileFullPath);
return;
}

unsigned long long offset;
if (![fileHandle seekToEndReturningOffset:&offset error:&error]) {

RollbarSdkLog(@" Error while seeking to file end of %@: %@", fileFullPath, [error localizedDescription]);
return;
}

if (![fileHandle writeData:data error:&error]) {

RollbarSdkLog(@" Error while writing data to %@: %@", fileFullPath, [error localizedDescription]);
return;
}

if (![fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding] error:&error]) {

RollbarSdkLog(@" Error while writing data to %@: %@", fileFullPath, [error localizedDescription]);
return;
}

if (![fileHandle closeAndReturnError:&error]) {

RollbarSdkLog(@" Error while closing %@: %@", fileFullPath, [error localizedDescription]);
return;
}
}

+ (void)appendSafelyData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath {

if (!data) {

RollbarSdkLog(@"No data to append!");
return;
}

// make sure the file exists:
if (NO == [RollbarFileWriter ensureFileExists:fileFullPath]) {

return;
}

// append-save the data into the file:
[RollbarFileWriter appendData:data toFile:fileFullPath];
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ NS_ASSUME_NONNULL_BEGIN

#pragma mark - Core API: data setters by key

- (void)setDictionary:(NSDictionary *)data forKey:(NSString *)key;
- (void)setArray:(NSArray *)data forKey:(NSString *)key;
- (void)setString:(NSString *)data forKey:(NSString *)key;
- (void)setNumber:(NSNumber *)data forKey:(NSString *)key;
- (void)setDictionary:(nullable NSDictionary *)data forKey:(NSString *)key;
- (void)setArray:(nullable NSArray *)data forKey:(NSString *)key;
- (void)setString:(nullable NSString *)data forKey:(NSString *)key;
- (void)setNumber:(nullable NSNumber *)data forKey:(NSString *)key;

#pragma mark - Convenience API

Expand Down
2 changes: 1 addition & 1 deletion RollbarCommon/Sources/RollbarCommon/include/RollbarDTO.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN

/// Checks if the provided object is transferrable (ie could be converted to/from JSON).
/// @param obj the object in question
+ (BOOL)isTransferableObject:(id)obj;
+ (BOOL)isTransferableObject:(nullable id)obj;

/// Checks if the provided object could be used as a DTO property/data value.
/// @param obj the object in question
Expand Down
24 changes: 24 additions & 0 deletions RollbarCommon/Sources/RollbarCommon/include/RollbarFileWriter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// RollbarFileWriter.h
//
//
// Created by Andrey Kornich on 2022-05-23.
//

@import Foundation;

NS_ASSUME_NONNULL_BEGIN

@interface RollbarFileWriter : NSObject

+ (BOOL)ensureFileExists: (nullable NSString *)fileFullPath;
+ (void)appendData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath;
+ (void)appendSafelyData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath;

/// Hides parameterless initializer.
- (instancetype)init
NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (void)testDetectAppBundleVersion {
NSString *version = [RollbarBundleUtil detectAppBundleVersion];
XCTAssertNotNil(version);
XCTAssertGreaterThan(version.length, 0);
XCTAssertEqual([version componentsSeparatedByString:@"."].count, 4);
XCTAssertGreaterThanOrEqual([version componentsSeparatedByString:@"."].count, 3);
}

- (void)testPerformanceDetectAppBundleVersion {
Expand Down
19 changes: 19 additions & 0 deletions RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ - (void)tearDown {
NSLog(@"Teared down.");
}

- (void)testSetDictionaryWithNothing {

RollbarDTO *dto = [[RollbarDTO alloc] initWithDictionary:@{}];
XCTAssertNotNil(dto);
XCTAssertNil([dto getDataByKey:@"key"]);

[dto setDictionary:NULL forKey:@"key"];
XCTAssertNil([dto getDataByKey:@"key"]);

[dto setDictionary:Nil forKey:@"key"];
XCTAssertNil([dto getDataByKey:@"key"]);

[dto setDictionary:nil forKey:@"key"];
XCTAssertNil([dto getDataByKey:@"key"]);

[dto setDictionary:@{} forKey:@"key"];
XCTAssertNotNil([dto getDataByKey:@"key"]);
}

- (void)testRollbarTaskDispatcher {

void (^task)(id) = ^(id taskInput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ - (void)testOsVersionDetection {
NSOperatingSystemVersion version = [RollbarOsUtil detectOsVersion];
NSString *versionString = [RollbarOsUtil stringFromOsVersion:version];
NSString *detectedVersionString = [RollbarOsUtil detectOsVersionString];
XCTAssertTrue([detectedVersionString containsString:versionString]);
XCTAssertTrue([detectedVersionString containsString:[versionString componentsSeparatedByString:@"."][0]]);
XCTAssertTrue([detectedVersionString containsString:[versionString componentsSeparatedByString:@"."][1]]);
}

- (void)testDetectOsUptimeInterval {
Expand Down
6 changes: 3 additions & 3 deletions RollbarDeploys.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Pod::Spec.new do |s|
# s.resources = "Resources/*.png"

# When using multiple platforms:
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.11"
s.tvos.deployment_target = "11.0"
s.osx.deployment_target = "10.15"
s.ios.deployment_target = "13.0"
s.tvos.deployment_target = "13.0"
# s.watchos.deployment_target = "4.0"
# Any platform, if omitted:
# s.platform = :ios
Expand Down
Loading

0 comments on commit 8ab423b

Please sign in to comment.