Skip to content
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

Make ParseErrorKind public and available through ParseError::kind() #588

Merged
merged 6 commits into from Jun 9, 2022

Conversation

sbrocket
Copy link
Contributor

ParseErrorKind has also been made #[non_exhaustive] to avoid committing
to only the current set of error kinds, i.e. so that it can be expanded
as needed without an SemVer-breaking change.

Thanks for contributing to chrono!

  • Have you added yourself and the change to the changelog? (Don't worry
    about adding the PR number)
  • If this pull request fixes a bug, does it add a test that verifies that
    we can't reintroduce it?

Fixes #319

ParseErrorKind has also been made #[non_exhaustive] to avoid committing
to only the current set of error kinds, i.e. so that it can be expanded
as needed without an SemVer-breaking change.
@Toover
Copy link

Toover commented Dec 5, 2021

I find the PR good but I wonder why there is a notion of "kind" involved whereas a synonymous notion is provided by the "type" system. Can't ParseError just be an enum and all kinds be values? Sorry if that is a noob question.

@sbrocket
Copy link
Contributor Author

sbrocket commented Dec 7, 2021

Can't ParseError just be an enum and all kinds be values?

Yes, ParseError could have directly been an enum instead of there being a separate ParseErrorKind enum type. Switching it from a struct to an enum now, however, would be a breaking change.

@Toover
Copy link

Toover commented Dec 8, 2021

Switching it from a struct to an enum now, however, would be a breaking change.

Sorry I am still learning Rust... Given that it has been private until now, why would it break? Is it because the ABI of a struct differs from the one of an enum? So the needed memory allocation won't be right with that new version, unless it is recompiled?

@sbrocket
Copy link
Contributor Author

sbrocket commented Dec 8, 2021 via email

@PumpkinSeed
Copy link

Thanks for the contribution, I just run into an issue which solved by this PR, because I can't return ParseResult in one of my functions, because the ParseErrorKind is private and I want to return Err(ParseError(ParseErrorKind::Invalid)).

@sbrocket
Copy link
Contributor Author

Thanks for the contribution, I just run into an issue which solved by this PR, because I can't return ParseResult in one of my functions, because the ParseErrorKind is private and I want to return Err(ParseError(ParseErrorKind::Invalid)).

Thank you but I don’t think this change will actually help with that usage. This leaves the field inside the tuple struct private, so I don’t think you would be able to construct your own ParseError value.

@sbrocket
Copy link
Contributor Author

Maintainers, I haven’t resolved the CHANGELOG.md conflict because it isn’t clear if or when this PR will be looked at, and it seemed likely the conflict would reoccur. If you’re ignoring this because of the conflict please let me know and I’ll fix it, otherwise I would appreciate feedback one way or the other. Thanks.

@ritchie46
Copy link

This would also be a valuable addition for us. We want to match the minimal possible values from contiguous slices of possible matches. Not having to materialize the string errors would save a lot of allocations.

@Ploppz
Copy link
Contributor

Ploppz commented May 12, 2022

Why is this not yet merged?

@djc
Copy link
Contributor

djc commented May 12, 2022

The previous maintainer left, and other changes have taken priority. Once CI passes I'm happy to review this.

@Ploppz
Copy link
Contributor

Ploppz commented May 12, 2022

Looking at the test results, #[non_exhaustive] seems to be unsupported in Rust 1.32. Does chrono state a MSRV? Is there a reason why tests are using rustc 1.32 - can this be increased to the current stable version?

@djc
Copy link
Contributor

djc commented May 12, 2022

Yes, 1.32 is the current MSRV for the main branch and will be for the next release, so #[non_exhaustive] is not available.

@Ploppz
Copy link
Contributor

Ploppz commented May 12, 2022

Is it an option to implement it like this in the meantime? https://rust-lang.github.io/rfcs/2008-non-exhaustive.html#how-we-do-this-today

@djc
Copy link
Contributor

djc commented May 12, 2022

Yeah, that's probably an okay solution for now. Probably should add a comment with a // TODO: MSRV.

@Ploppz
Copy link
Contributor

Ploppz commented May 13, 2022

Feel free to already review my changes sbrocket#1

@sbrocket
Copy link
Contributor Author

Done, thanks @Ploppz!

@Ploppz
Copy link
Contributor

Ploppz commented May 13, 2022

Np! I guess it's up to you to either rebase or merge from main to resolve conflicts.

@sbrocket
Copy link
Contributor Author

I’ll leave it up to the maintainer to handle the changelog conflict, since I have no idea when this might be reviewed and would otherwise need to repeatedly resolve conflicts there.

@djc
Copy link
Contributor

djc commented May 13, 2022

Please just rebase this and fix the merge conflict. I don't have time to resolve conflicts for every PR -- I will review this pretty soon once it passes CI.

@sbrocket
Copy link
Contributor Author

Ok, rebased (once; hopefully it makes sense that expecting all authors of pending PRs to rebase their PRs every time the changelog is updated by another merged PR is not a very smooth contribution process). CI isn't going to run automatically because of the first-time contributor approval limitation.

@Ploppz
Copy link
Contributor

Ploppz commented May 25, 2022

I hope it's not out of place with a gentle reminder. Additional question: can this be included in the next version / what's the timeline for the next version release?

@djc
Copy link
Contributor

djc commented May 25, 2022

It should be in the next release. That's mainly waiting for the work in #677 and related PRs. Rest assured that this is still in my GitHub notifications queue and won't be forgotten (that is, no need to remind me again).

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.

Support introspection of ParseError?
6 participants