From 610abb42025a28789c547ca45c01931ee3f6d9bb Mon Sep 17 00:00:00 2001 From: Siemen Sikkema Date: Wed, 15 May 2019 20:51:34 +0200 Subject: [PATCH 1/5] Remove request debug description This could contain sensitive information and was not filtered --- Sources/Bugsnag/Bugsnag.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Bugsnag/Bugsnag.swift b/Sources/Bugsnag/Bugsnag.swift index 76f70e2..c133dbe 100644 --- a/Sources/Bugsnag/Bugsnag.swift +++ b/Sources/Bugsnag/Bugsnag.swift @@ -45,8 +45,7 @@ struct BugsnagEvent: Encodable { self.exceptions = [BugsnagException(error: error, stacktrace: stacktrace)] self.metaData = BugsnagMetaData( meta: [ - "Error localized description": error.localizedDescription, - "Request debug description": httpRequest.debugDescription + "Error localized description": error.localizedDescription ].merging(metadata.mapValues { $0.debugDescription }) { a, b in b } ) self.payloadVersion = payloadVersion From 59564d4e9d98b6aa9effd6346b13bb52816c95af Mon Sep 17 00:00:00 2001 From: Siemen Sikkema Date: Wed, 15 May 2019 21:02:53 +0200 Subject: [PATCH 2/5] Add additional error information --- Sources/Bugsnag/Bugsnag.swift | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Sources/Bugsnag/Bugsnag.swift b/Sources/Bugsnag/Bugsnag.swift index c133dbe..470eb8b 100644 --- a/Sources/Bugsnag/Bugsnag.swift +++ b/Sources/Bugsnag/Bugsnag.swift @@ -43,10 +43,23 @@ struct BugsnagEvent: Encodable { self.app = app self.breadcrumbs = breadcrumbs self.exceptions = [BugsnagException(error: error, stacktrace: stacktrace)] - self.metaData = BugsnagMetaData( - meta: [ - "Error localized description": error.localizedDescription - ].merging(metadata.mapValues { $0.debugDescription }) { a, b in b } + + let nsError = error as NSError + let errorCode: Int? = nsError.code == 0 ? nil : nsError.code + let userInfo = nsError.userInfo.compactMapValues { $0 as? String } + + self.metaData = BugsnagMetaData(meta: [ + "Error code": errorCode?.description, + "Error domain": nsError.domain, + "Error localized description": error.localizedDescription, + "Error localized failure reason": nsError.localizedFailureReason, + "Error localized recovery options": nsError.localizedRecoveryOptions? + .joined(separator: ","), + "Error localized recovery suggestion": nsError.localizedRecoverySuggestion + ] + .compactMapValues { $0 } + .merging(userInfo) { a, b in b } + .merging(metadata.mapValues { $0.debugDescription }) { a, b in b } ) self.payloadVersion = payloadVersion self.request = httpRequest.map { BugsnagRequest(httpRequest: $0, keyFilters: keyFilters) } From bee7d5717f789f9c0cf7f61d708efb875dd843e7 Mon Sep 17 00:00:00 2001 From: Siemen Sikkema Date: Thu, 16 May 2019 06:58:09 +0200 Subject: [PATCH 3/5] Include more values by using String(describing:) --- Sources/Bugsnag/Bugsnag.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Bugsnag/Bugsnag.swift b/Sources/Bugsnag/Bugsnag.swift index 470eb8b..9164995 100644 --- a/Sources/Bugsnag/Bugsnag.swift +++ b/Sources/Bugsnag/Bugsnag.swift @@ -46,7 +46,7 @@ struct BugsnagEvent: Encodable { let nsError = error as NSError let errorCode: Int? = nsError.code == 0 ? nil : nsError.code - let userInfo = nsError.userInfo.compactMapValues { $0 as? String } + let userInfo = nsError.userInfo.mapValues { String(describing: $0) } self.metaData = BugsnagMetaData(meta: [ "Error code": errorCode?.description, From 7662192ea937d4578668fe75e697f3b2e8c56f5c Mon Sep 17 00:00:00 2001 From: Siemen Sikkema Date: Thu, 16 May 2019 06:58:18 +0200 Subject: [PATCH 4/5] Bump to Swift 4.2 --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 689f993..cc2a45b 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.1 +// swift-tools-version:4.2 import PackageDescription let package = Package( From 70e7754e747ca1545c5cfb569a63b7a4ac16b6e9 Mon Sep 17 00:00:00 2001 From: Siemen Sikkema Date: Thu, 16 May 2019 07:35:20 +0200 Subject: [PATCH 5/5] Add compactMapValues for swift < 5 --- Sources/Bugsnag/Bugsnag.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/Bugsnag/Bugsnag.swift b/Sources/Bugsnag/Bugsnag.swift index 9164995..cf96c2b 100644 --- a/Sources/Bugsnag/Bugsnag.swift +++ b/Sources/Bugsnag/Bugsnag.swift @@ -68,6 +68,18 @@ struct BugsnagEvent: Encodable { } } +#if swift(>=5.0) +#else + extension Dictionary { + func compactMapValues(_ transform: (Value) throws -> T?) rethrows -> [Key : T] { + return try .init(uniqueKeysWithValues: compactMap { + guard let value = try transform($0.value) else { return nil } + return ($0.key, value) + }) + } + } +#endif + struct BugsnagException: Encodable { let errorClass: String let message: String