Skip to content

Conversation

@kaushalkapasi
Copy link
Collaborator

  • fix: update the Feature struct constructor to accept a dictionary of type [ String: Any ] to allow values to be of type other than String
  • fix: add if let protection when parsing the featureMap and variablesMap on the UserConfig to prevent errors from JSON parsing to cause SDK crashes, instead we will log warnings

@kaushalkapasi kaushalkapasi marked this pull request as ready for review June 6, 2025 21:03
guard let variationName = dictionary["variationName"] else { throw UserConfigError.MissingProperty("variationName in Feature object") }
init (from dictionary: [String: Any]) throws {
guard let id = dictionary["_id"] as? String else {
throw UserConfigError.MissingProperty("_id in Feature object")
Copy link
Member

Choose a reason for hiding this comment

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

update these error messages to say we expect these to be typed as strings.

@kaushalkapasi kaushalkapasi force-pushed the fix-improve-json-parsing-error-handling branch from af95065 to 60230d1 Compare June 9, 2025 15:47
}


func testSuccessfulConfigParsingWithNonStringValuesOnFeatures() throws {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we actually add a test that uses test configs that have unknown properties in all parts of the config instead of just the feature?

Copy link
Member

Choose a reason for hiding this comment

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

Yea can we add a test that shows it throwing for UserConfigError.InvalidProperty and UserConfigError.MissingProperty above? Also a test that shows that these errors don't propagate past the config fetching.

@kaushalkapasi kaushalkapasi force-pushed the fix-improve-json-parsing-error-handling branch from b6e88cb to 57e2933 Compare June 9, 2025 20:11
self.features = features
} else {
Log.warn("Invalid feature map format", tags: ["config", "JSONParsing"])
throw UserConfigError.InvalidProperty("features")
Copy link
Member

Choose a reason for hiding this comment

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

So where are these errors caught?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These errors are caught by DevCycleService.getConfig completion handler of the method, defined as: completion: @escaping ConfigCompletionHandler)

@kaushalkapasi kaushalkapasi force-pushed the fix-improve-json-parsing-error-handling branch from 57e2933 to deae363 Compare June 9, 2025 20:51
@kaushalkapasi kaushalkapasi merged commit a079824 into main Jun 10, 2025
8 of 11 checks passed
@kaushalkapasi kaushalkapasi deleted the fix-improve-json-parsing-error-handling branch June 10, 2025 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants