Skip to content

Separate error description vs localizedDescription #730

@weissi

Description

@weissi

Description

In pure Swift programs it's quite important to not call .localizedDescription on random error types -- unless they are verified to be proper NSErrors. Unfortunately, ClientError's description does just that.

Consider this Swift program

import Foundation

public enum SomeSwiftError: Error {
    case aFailed
    case bFailed
}

do {
    throw SomeSwiftError.bFailed
} catch {
    print("correct (just print)", error)
    print("incorrect (localizedDescription)", error.localizedDescription)
}

the output is

$ swiftc bad.swift && ./bad
correct (just print) bFailed
incorrect (localizedDescription) The operation couldn’t be completed. (bad.SomeSwiftError error 1.)

See how localizedDescription just prints The operation couldn’t be completed. (TYPE error 1.). Even the error number is statically just 1.


Bottom line: If I do print(errorFromOpenAPIRuntime) I always get The operation couldn’t be completed. (AsyncHTTPClientError error 1.) with no further information.


Underlying bug is swiftlang/swift#58724

Reproduction

n/a

Package version(s)

latest

Expected behavior

prints the correct error, crucially it must never call localizedDescription.

Environment

all

Additional information

No response

Metadata

Metadata

Assignees

Labels

area/runtimeAffects: the runtime library.good first issueGood for newcomerskind/bugFeature doesn't work as expected.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions