Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWIFT 6 : Thread 41: EXC_BREAKPOINT (code=1, subcode=0x103330448) #229

Open
insightsoft opened this issue Sep 24, 2024 · 2 comments
Open

Comments

@insightsoft
Copy link

insightsoft commented Sep 24, 2024

Hi guys,

Hello,
I'm encountering an issue where my code breaks at the following line. The same code works flawlessly in Swift 5.x, but in Swift 6 (as detailed below), it throws an error.

Is anyone else experiencing this behavior? Could this be an expected issue due to Swift 6 still being unreleased?

Thank you in advance for any insights!

@insightsoft
Copy link
Author

Hi guys,

Hello, I'm encountering an issue where my code breaks at the following line. The same code works flawlessly in Swift 5.x, but in Swift 6 (as detailed below), it throws an error.

Is anyone else experiencing this behavior? Could this be an expected issue due to Swift 6 still being unreleased?

Thank you in advance for any insights!

extension OpenAI {

    func performRequest<ResultType: Codable>(request: any URLRequestBuildable, completion: @escaping (Result<ResultType, Error>) -> Void) {
        do {
            let request = try request.build(token: configuration.token, 
                                            organizationIdentifier: configuration.organizationIdentifier,
                                            timeoutInterval: configuration.timeoutInterval)
            let task = session.dataTask(with: request) { data, _, error in
                if let error = error {
                    return completion(.failure(error))
                }
                guard let data = data else {
                    return completion(.failure(OpenAIError.emptyData))
                }
                let decoder = JSONDecoder()
                do {
HERE:				completion(.success(try decoder.decode(ResultType.self, from: data)))
                } catch {
                    completion(.failure((try? decoder.decode(APIErrorResponse.self, from: data)) ?? error))
                }
            }
            task.resume()
        } catch {
            completion(.failure(error))
        }
    }
...

@insightsoft
Copy link
Author

I solve my problem with:

let decoder = JSONDecoder()

            do {
                let decodedResponse = try decoder.decode(ResultType.self, from: data)
                print("Decoded Response: \(decodedResponse)")
                
                **DispatchQueue.main.async {
                    completion(.success(decodedResponse))
                }**
            } catch {
                print("Decoding Error: \(error)")
                
                DispatchQueue.main.async {
                    completion(.failure(error))
                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant