I made a stupid mistake this week

I made a stupid mistake this week that I submitted a merge request causing a model parsing error on production environment. I had written a function with a do-catch block in it but forgetting to write the catch block only one do block. Usually, the Xcode compiler will detect this missing and throws a compilation error. But that function is a throws function that silenced the error.

The logic of the method is roughly as follows:

1
2
3
4
5
6
7
8
9
10
11
func parse<T>(keys: [String]) throws -> T {
for (index, key) in keys.enumerated {
if index == keys.count - 1 {
return try decoder.decode(key)
} else {
do {
return try decoder.decode(key)
}
}
}
}

The question is the else block that has a do block but doesn’t cache errors. It caused that subsequent keys didn’t be tried if the first key thrown an error.