アプリを実行して要求ユーティリティを使用するたびに、奇妙なクラッシュが発生します。
これはXCode Beta 13.5にあります
私も Thread Sanitizer を使用していることに言及する必要があります。このエラーは、Thread Sanitizer がオンになっている場合にのみ表示されます。
コードは次のとおりです。
まず、クリックするとデータを送信するボタンがあります
Button(action: { Task { await viewModel.submitData() } } ) {
Text("Log In")
}
これは submitData 関数です
func submitData() async -> Void {
state = .loading
do {
let result = try await AuthenticationAPI.login(user: user)
self.state = .success
self.authenticator.authenticate(token: result.value.token)
} catch let error as APIError {
self.handleAPIError(error)
} catch {
// TODO: Log Error
self.handleAPIError(.unexpectedError)
}
}
これは AuthenticationAPI.login 関数です
static func login(user: LoginUser) async throws -> APIService.Response<AuthenticatedUser> {
let endpoint = Endpoint.login
let data = try? encode(user.toDictionary())
return try await apiService.post(type: AuthenticatedUser.self,
url: endpoint.url, body: data)
}
最後に、これはネットワーク呼び出しです
func executeRequest<T: Decodable>(_ request: URLRequest) async throws -> Response<T> {
guard let (data, response) = try? await URLSession.shared.data(for: request) else {
throw APIError.networkError
}
if let response = response as? HTTPURLResponse {
if (200...299).contains(response.statusCode) {
guard let data = try? decoder.decode(T.self, from: data) else {
throw APIError.decodingError
}
return Response(value: data, response: response)
} else if (400...499).contains(response.statusCode) {
throw APIError.httpError(data, response)
} else if response.statusCode == 500 {
throw APIError.serverError
}
}
throw APIError.unexpectedError
}
func post<T: Decodable>(
type: T.Type,
url: URL,
headers: Headers = [:],
body: Data?
) async throws -> Response<T> {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = body
constructHeaders(request: &request, headers: headers)
return try await executeRequest(request) // This is where the compiler tells me the error occurs
}
executeRequest 関数は、要求を作成しないため呼び出されません (ローカル サーバーを確認しました)。
これらはスレッド ログです。
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x00007fff30bb03f4 in swift::TargetMetadata<swift::InProcess>::isCanonicalStaticallySpecializedGenericMetadata() const ()
#1 0x00007fff30bbc7b1 in swift_checkMetadataState ()
#2 0x00007fff30b713d5 in type metadata completion function for ClosedRange<>.Index ()
#3 0x00007fff30bbf75d in swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()
#4 0x00007fff30bb1941 in _swift_getGenericMetadata(swift::MetadataRequest, void const* const*, swift::TargetTypeContextDescriptor<swift::InProcess> const*) ()
#5 0x00007fff30b8b440 in __swift_instantiateCanonicalPrespecializedGenericMetadata ()
#6 0x00000001017f9e00 in APIService.post<τ_0_0>(type:url:headers:body:) at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/Services/APIService.swift:124
#7 0x00000001017a0dd0 in static AuthenticationAPI.login(user:) at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/Networking/Authentication/AuthenticationAPI.swift:21
#8 0x000000010170b3c0 in LoginViewModel.submitData() at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/App/Login/ViewModels/LoginViewModel.swift:42
#9 0x00000001016317d0 in closure #1 in closure #1 in closure #2 in closure #1 in closure #1 in LoginView.body.getter at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/App/Login/Views/LoginView.swift:26
#10 0x0000000101637960 in partial apply for closure #1 in closure #1 in closure #2 in closure #1 in closure #1 in LoginView.body.getter ()
#11 0x0000000101631ae0 in thunk for @escaping @callee_guaranteed @Sendable @async () -> () ()
#12 0x0000000101637ac0 in partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> () ()
#13 0x00000001016353f0 in thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out τ_0_0) ()
#14 0x0000000101637d70 in partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out τ_0_0) ()