Skip to content

Add SE proposal for Codable error printing #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZevEisenberg
Copy link
Contributor

@ZevEisenberg ZevEisenberg commented May 10, 2025

SE proposal to accompany swiftlang/swift#80941

@stephentyrone
Copy link
Contributor

Hi @ZevEisenberg, I'm really excited about this. Can you begin a pitch thread on the forums, and then we can work on getting it ready for formal evolution review in a few weeks?

@ZevEisenberg
Copy link
Contributor Author


## Implications on adoption

[Unsure what to add here. I see stuff in [SE-0445](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0445-string-index-printing.md#implications-on-adoption), but I'm not sure how much of that applies here. I don't know if I need to be doing the `@backDeployed` things that proposal mentions, and when I look at the code from the PR, I see `@_alwaysEmitIntoClient // FIXME: Use @backDeployed`.]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that in SE-0445 the back-deploying was important because the non-API public symbol _description existed on String.Index in prior Swift versions, and was reimplemented using debugDescription? I'm not certain that this is quite as relevant here, which suggests that there's nothing really useful to add to this section.

@lorentey can you provide any background on SE-0445 and/or advice here?

@ZevEisenberg
Copy link
Contributor Author

@xwu I saw that you self-assigned this. I just got this PR and my implementation PR rebased on main, and confirmed that the implementation still builds and passes tests when I run it locally. Is there anything I can or should be doing to help get this ready for proposal phase? Do you have a sense of whether it would land in Swift 6.2 or main?

@xwu
Copy link
Contributor

xwu commented Jun 11, 2025

I'll do an editorial pass later this week (or weekend) and have suggestions to help you fill out all the parts of the proposal text. Once it's taken out of draft status, I'll get back to you after the language steering group is satisfied it's ready to run as a proposal and schedule the review period, which will run over two weeks.

Implementation work proceeds separately; after a feature lands in main (which would be no earlier than July given the timeline above), then it can be evaluated if cherrypicking to a release branch is appropriate, but expect it's well out of the window for 6.2.


(Note: the output could be further improved by modifying `JSONDecoder` to write a better debug description. See [Future Directions](#future-directions) for more.)

### Structure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we don't guarantee the format of a description or debug description; giving a specific rundown of what information will be presented, under what conditions, and in which order reads like a guarantee that doesn't seem necessary to achieve your motivation (and we don't want users to be parsing this programmatically).

I would suggest either removing this information or phrasing this more as an example of how the implementation might improve usability—as well as explicitly noting, as we did in SE-0445, that it is not normative and is subject to future change without review or advance notice.


## Implications on adoption

[Unsure what to add here. I see stuff in [SE-0445](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0445-string-index-printing.md#implications-on-adoption), but I'm not sure how much of that applies here. I don't know if I need to be doing the `@backDeployed` things that proposal mentions, and when I look at the code from the PR, I see `@_alwaysEmitIntoClient // FIXME: Use @backDeployed`.]
Copy link
Contributor

@xwu xwu Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I might say: The conformance being proposed here is not backdeployable. As a result, code that runs on ABI-stable platforms with earlier versions of the standard library won't output these nicer debug descriptions.

It is up to you if you want to make debugDescription itself (the property, not the conformance) backdeployable—this would make it possible for newly compiled code to invoke debugDescription explicitly if they absolutely need the nicer description, but that is not something we would either recommend or expect users to reach for pervasively to work around the adoption issue outlined above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if we back-deployed debugDescription, and if someone knew about this change, they would be able to ship an update that would work even when running on OSes that don't have the change? But only if they explicitly called debugDescription instead of just logging the errors with default string interpolation or whatever method they are using now?

Since the information in question is primarily for use as a developer convenience while debugging, I'm inclined to go the simpler route. If you're digging around in error logs, and you think of looking into this and learn about the debugDescription hack, I figure you're probably savvy enough to just read the old-style error message yourself?

Copy link
Contributor

@xwu xwu Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that part is a design decision and not a proposal drafting decision, so I leave it to you :)


The original version of this proposal suggested conforming `EncodingError` and `DecodingError` to `CustomStringConvertible`, not `CustomDebugStringConvertible`. The change to the debug-flavored protocol emphasizes that the new descriptions aren't intended to be used outside debugging contexts. This is in keeping with the precedent set by [SE-0445](0445-string-index-printing.md).

The original version also proposed changing `CodingKey.description` to return the bare string or int value, but changing the exsting implementation of an existing public method was deemed too potentially dangerous.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify what you mean here by "dangerous"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was in reference to swiftlang/swift#80941 (comment). I'll update the proposal, plus I'll link to that thread if appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I understand the point correctly, "dangerous" is referring concretely to Foundation.JSONDecoder having a known dependency on non-guaranteed implementation details of CodingKey.description?

Copy link
Contributor Author

@ZevEisenberg ZevEisenberg Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! I'm thinking "dangerous" is not the right word, and @kperryua's original message or your summary is closer to what we should put here in the proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants