error handling - Xcode shows error since Xcode Version > 15

Hello together,

since Xcode Version > 15 the following error handling causes following error "Pattern of type 'DecodingError' cannot match 'Never'

func getSupportedCountries() async {
        
        // fetch all documents from collection "seasons" from firestore
        let queryCountries = try? await db.collection("countries").getDocuments()
        
        if queryCountries != nil {
            self.countries = (queryCountries!.documents.compactMap({ (queryDocumentSnapshot) -> Country? in
                let result = Result { try? queryDocumentSnapshot.data(as: Country.self) }

                switch result {
                case .success(let country):
                    if let country = country {
                        // A country value was successfully initialized from the DocumentSnapshot
                        self.errorMessage = nil
                        return country
                    }
                    else {
                        // A nil value was successfully initialized from the DocumentSnapshot,
                        // or the DocumentSnapshot was nil
                        self.errorMessage = "Document doesn't exist."
                        return nil
                    }
                    
                case .failure(let error):
                    // A Country value could not be initialized from the DocumentSnapshot
                    switch error {
                    case DecodingError.typeMismatch(_, let context):
                        self.errorMessage = "\(error.localizedDescription): \(context.debugDescription)"
                    case DecodingError.valueNotFound(_, let context):
                        self.errorMessage = "\(error.localizedDescription): \(context.debugDescription)"
                    case DecodingError.keyNotFound(_, let context):
                        self.errorMessage = "\(error.localizedDescription): \(context.debugDescription)"
                    case DecodingError.dataCorrupted(let key):
                        self.errorMessage = "\(error.localizedDescription): \(key)"
                    default:
                        self.errorMessage = "Error decoding document: \(error.localizedDescription)"
                    }
                    return nil
                }
            }))
        } else {
            self.errorMessage = "No documents in 'countries' collection"
            return
        }
}

the interesting part of the code where XCODE shows an error is from "switch error" downwards.

Does anyone of you have an idea what's wrong?

Ay help appreciated !

Thx, Peter

It’s hard to offer any insight into this without being able to reproduce the failure. Can you create a cut down test project that shows the problem?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I can't even compile/build the project

I’m sorry but I can’t help you from a screenshot of the problem. Please post text rather than screenshots. See tip 6 in Quinn’s Top Ten DevForums Tips.

It would help if that was code that I can build here to see the issue for myself. Ideally that would be a small test project, as described in Creating a test project.

One benefit of creating a test project is that the act of doing that might help you to find and fix the issue yourself.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

error handling - Xcode shows error since Xcode Version > 15
 
 
Q