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

Constrain Parsed Error to Swift Error #57

Merged
merged 6 commits into from
Jan 6, 2025
Merged

Conversation

ajevans99
Copy link
Owner

Description

This PR updates the Parsed<Value, Error> enum to constrain the Error generic to conform to Swift.Error. This change ensures semantic clarity, improves type safety, and enables better integration with Swift’s error-handling mechanisms.

Closes #56

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Additional Notes

Add any other context or screenshots about the pull request here.


Note: You can add the auto-format label to this pull request to enable automatic Swift formatting.

@gsabran
Copy link
Contributor

gsabran commented Jan 5, 2025

Thanks!

What do you think of also adding a conformance to LocalizedError ? I tried to gave it a go, but for some cases I was not sure what was the best description:

extension ParseIssue: LocalizedError {
  public var errorDescription: String? {
    switch self {
      case typeMismatch(let expected, let actual):
        return "Type mismatch. Expecting \(expected.rawValue) and got \(actual.primative.rawValue): \(actual.description.prefix(20)"
      case noEnumCaseMatch(let value):
        return ...
      case missingRequiredProperty(let property)
        return "Missing required property `\(property)`"
      case compactMapValueNil(let value)
        return ...
      case compositionFailure(let type, let reason, let nestedErrors)
        return ...
    }
  }
}

@ajevans99
Copy link
Owner Author

How about this? Conform to CustomStringConvertible

I'm not sure about using LocalizedError in the library like that. I'm trying to avoid a dependency on Foundation (with the exception of URL in validation) and I think it might be a bit misleading since the values are not actually localized. Also, this is more consistent with ValidationIssue.

Copy link
Contributor

@gsabran gsabran left a comment

Choose a reason for hiding this comment

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

This is great!

ajevans99 and others added 3 commits January 6, 2025 12:01
Co-authored-by: Guillaume Sabran <sabranguillaume@gmail.com>
Co-authored-by: Guillaume Sabran <sabranguillaume@gmail.com>
@ajevans99 ajevans99 merged commit 33491db into main Jan 6, 2025
8 checks passed
@ajevans99 ajevans99 deleted the parse-issue-as-error branch January 6, 2025 17:39
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.

Should Parsed<Value, Error> be Parsed<Value, Err: Error> ?
2 participants