Properly handling errors when calculating DB stats