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

return null with pathConfiguredFailedToParse exception #91

Closed

Conversation

williamkennedy
Copy link

When I was exploring the codebase, I noticed this issue and changed the return value to null in the case of an exception on parsing malformed json.

Comment on lines -70 to +72
null
fun load(json: String): PathConfiguration? {
return try {
json.toObject(object : TypeToken<PathConfiguration>() {})
} catch (e: Exception) {
logError("pathConfiguredFailedToParse", e)
null
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't actually change any logic here. In Kotlin, = try is just shorthand for return try. Looking at this closer, we're already catching parsing exceptions correctly, just with a slightly different implementation from turbo-android.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's what I noticed when I started this. I meant to look into it further, but I became busy with work.

Thanks for coming back to it.

Comment on lines +56 to +68
@Test
fun getMalformedRemoteConfiguration() {
enqueueResponse("malformed-body.json")
val loader = PathConfigurationLoader(context)

runBlocking {
launch(Dispatchers.Main) {
val json = repository.getRemoteConfiguration(baseUrl())
val pathConfiguration = json?.let { loader.load(it) }
assertThat(pathConfiguration).isNull()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The more appropriate place for this test is in PathConfigurationTest, since parsing exceptions are caught at the PathConfigurationLoader layer, not the repository layer.

@jayohms
Copy link
Contributor

jayohms commented Jan 27, 2025

Tests were added here: #93

@jayohms jayohms closed this Jan 27, 2025
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.

2 participants