async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

AHC errors have bad `.localizedDescription` (always claims `error 1`)

Open weissi opened this issue 11 months ago • 0 comments

I'm using a library that unfortunately does logger[metadataKey: "request.error"] = .string(error.localizedDescription) where the error is an error out of AHC. The result is that it always prints

request.error=The operation couldn’t be completed. (AsyncHTTPClient.HTTPClientError error 1.)

Note that error 1 is produced regardless of the actual error.


The source of the problem is this oddity in Swift/Foundation:

import Foundation

struct MyError: Error & CustomStringConvertible { var description: String { "hello" } } 
print((MyError() as Error).localizedDescription)

// produces: "The operation couldn’t be completed. (MyError error 1.)"

weissi avatar Dec 18 '24 15:12 weissi