Skip to content

Commit 15de7f3

Browse files
committed
Send encountered errors to TreasureData
1 parent 1981571 commit 15de7f3

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

iCookTV/Debug.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ struct Debug {
4949
////////////////////////////////////////////////////////////////////////////////
5050

5151

52-
private extension String {
52+
extension String {
5353

5454
var typeName: String {
5555
return lastPathComponent.stringByDeletingPathExtension
5656
}
5757

58-
var lastPathComponent: String {
58+
private var lastPathComponent: String {
5959
return (self as NSString).lastPathComponent
6060
}
6161

62-
var stringByDeletingPathExtension: String {
62+
private var stringByDeletingPathExtension: String {
6363
return (self as NSString).stringByDeletingPathExtension
6464
}
6565

iCookTV/HistoryManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct HistoryManager {
5151
do {
5252
return try records.map { try JSON(data: $0) }
5353
} catch {
54-
Debug.print(error)
54+
Tracker.track(error)
5555
return [JSON]()
5656
}
5757
} else {
@@ -88,7 +88,7 @@ struct HistoryManager {
8888
let data = try records.map { try $0.serialize() } as NSArray
8989
data.writeToFile(path, atomically: true)
9090
} catch {
91-
Debug.print(error)
91+
Tracker.track(error)
9292
}
9393
}
9494
}
@@ -107,7 +107,7 @@ struct HistoryManager {
107107
completion?(success: true)
108108
}
109109
} catch {
110-
Debug.print(error)
110+
Tracker.track(error)
111111
dispatch_async(dispatch_get_main_queue()) {
112112
completion?(success: false)
113113
}

iCookTV/HistoryViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class HistoryViewController: VideosViewController {
5454
self.isLoading = false
5555
}
5656
} catch {
57-
Debug.print(error)
57+
Tracker.track(error)
5858
// Remove the malformed cache.
5959
HistoryManager.deleteCache() { _ in
6060
self.isLoading = false

iCookTV/Tracker.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,19 @@ enum Tracker {
4848
}
4949
}
5050

51-
static func track(error: ErrorType?) {
51+
static func track(error: ErrorType?, file: String = #file, function: String = #function, line: Int = #line) {
52+
guard let error = error else {
53+
return
54+
}
5255
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
53-
let description = (error as? NSError)?.localizedDescription ?? "\(error)"
56+
let description = String(error)
5457
Debug.print(description)
5558
Answers.logCustomEventWithName("Error", customAttributes: ["Description": description])
56-
TreasureData.sharedInstance().addEvent(["description": description], database: name, table: "errors")
59+
TreasureData.sharedInstance().addEvent([
60+
"description": description,
61+
"function": "\(file.typeName).\(function)",
62+
"line": line
63+
], database: name, table: "errors")
5764
}
5865
}
5966

iCookTV/VideoPlayerController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class VideoPlayerController: AVPlayerViewController, Trackable {
9595
self?.setPlayerItem($0)
9696
}
9797
} catch {
98-
Debug.print(error)
98+
Tracker.track(error)
9999
self?.setPlayerItem(nil)
100100
}
101101
}

0 commit comments

Comments
 (0)