-1

In trying to run tests on my app in Swift, I am encountering a problem. I do not have any breakpoints set, and yet, the execution of the tests is being interrupted on the line containing "throw errorResult", with this:

Thread 23: EXC_BREAKPOINT (code=1, subcode=0x180d7bc70)

This error is handled as you can see in the second code snippet. How can I prevent this from interrupting testing? This is expected behaviour that I am trying to test. This does not happen if I delete this line and instead throw a generic error.

 func doTheBiz<T: Decodable>(
    query: GQLQuery,
    serviceApiConfig: ServiceApiConfig
) async throws -> T {
    capturedQueryString = query.body
    
    if let successResult = successResult, let result = successResult as? T {
        return result
    } else if let errorResult = errorResult {
        throw errorResult // stops here
    } else {
        throw NSError.generic()
    }
}

This is the context for the call:

do {
    ...
    bizInfo = try await bizService.doTheBiz(...)
    ...
    self.state = .data
} catch {
    if state == .data { return }
    self.handleFailureResponse(error)
}

These tests ran absolutely fine in Xcode 16.2.

2
  • Are you sure you don't happen to have an exception breakpoint or Swift error breakpoint added to your project? Commented Jun 11 at 13:00
  • Yes, I'm sure. I have posted the actual reason as an answer. Commented Jun 11 at 13:01

1 Answer 1

0

This was happening because of the way we were mocking errors.

Old code:

mockBizService.errorResult = NSError()

New code:

mockBizService.errorResult = NSError(domain: "com.biz.test", code: 0, userInfo: nil)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.