swift-server / swift-server/async-http-client

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

Open
#797 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
1.1k
Forks
156
PR merge metrics
No merged PRs in 30d

Description

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.)"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing AsyncHTTPClient.HTTPClientError and its error-description behavior, then reproduce the reported localizedDescription output in Swift/Foundation. The fix is complete when AHC errors expose their actual error details instead of the generic “error 1” text; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.