Skip to content

Commit 4c91a85

Browse files
committed
Improve reason extraction from notable_addresses
1 parent 752ad1b commit 4c91a85

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Sources/Thread.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,34 @@ import Foundation
5656
}
5757

5858
#if swift(>=3.0)
59-
return notableAddresses.reduce(nil as String?) {prev, notableAddress in
59+
var result = notableAddresses.reduce("") { prev, notableAddress in
6060
let dict = notableAddress.1
6161
if let type = dict["type"] as? String, type == "string" {
62-
if let prev = prev,
63-
let value = dict["value"] as? String,
62+
if let value = dict["value"] as? String,
6463
value.components(separatedBy: " ").count > 3 {
64+
// we try to find a human readable sentence so we say there should be at least
65+
// 4 words e.g: unexpectedly found nil while unwrapping an Optional value
6566
return "\(prev)\(value) "
6667
}
6768
}
6869
return prev
6970
}
71+
result = result.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
7072
#else
71-
return notableAddresses.reduce(nil as String?) {prev, notableAddress in
73+
var result = notableAddresses.reduce("") { prev, notableAddress in
7274
let dict = notableAddress.1
7375
if let type = dict["type"] as? String where type == "string" {
74-
if let prev = prev,
75-
let value = dict["value"] as? String
76+
if let value = dict["value"] as? String
7677
where value.componentsSeparatedByString(" ").count > 3 {
7778
return "\(prev)\(value) "
7879
}
7980
}
8081
return prev
8182
}
83+
result = result.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
8284
#endif
85+
86+
return result.characters.count == 0 ? nil : result
8387
}
8488

8589
public override var debugDescription: String {

0 commit comments

Comments
 (0)