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

JSON encoding: lots of Codable-conforming types that crash in JSON encoding #301

Closed
jbbakst opened this issue Feb 28, 2024 · 3 comments · Fixed by #302
Closed

JSON encoding: lots of Codable-conforming types that crash in JSON encoding #301

jbbakst opened this issue Feb 28, 2024 · 3 comments · Fixed by #302
Assignees
Labels
enhancement New feature or request

Comments

@jbbakst
Copy link

jbbakst commented Feb 28, 2024

Describe the bug
There are many swift data types that crash in the library's JSON handling that (I believe) shouldn't. And since the type that the JSON object accepts in its initializer is [String: Any], the compiler can't catch any of these issues before runtime. This makes working with the library difficult (since you have to know which types are accepted and manually convert everything else to those types) and fragile (since you need to manually test each tracking call to ensure it doesn't crash the JSON logic).

To Reproduce
Steps to reproduce the behavior:

  1. Do segment.track(name: "Some Event Name", properties: ["key": value]) where the value is any of the following types (there are probably more, but these are the ones I've run into so far):
    • UUID
    • enum that conforms to Codable (e.g. enum MyEnum: String, Codable { case a, b, c })
  2. See the following error:
Segment/Utils.swift:54: Fatal error: A critical error occurred: jsonUnableToDeserialize(Segment.JSON.JSONError.nonJSONType(type: ...))

Expected behavior
Ideally, types that conform to Encodable and that can be properly serialized using a regular JSONEncoder should not crash in the library's handling of JSON

Platform (please complete the following information):

  • Library Version in use: 1.5.3
  • Platform being tested: iOS
@bsneed
Copy link
Contributor

bsneed commented Feb 28, 2024

Thanks @jbbakst, I'll have a look at what I can do about this. If you see Utils.swift line 54, this only happens in debug mode. Using the strongly typed version of track, what you're asking for should already work. For the more free-form dictionary stuff like you mention, there is a gap that could be improved for sure.

@bsneed
Copy link
Contributor

bsneed commented Feb 28, 2024

@jbbakst wanna give this branch a try? #302.

@jbbakst
Copy link
Author

jbbakst commented Feb 28, 2024

Nice! That looks good to me

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

Successfully merging a pull request may close this issue.

2 participants