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

Handle duplicate child key errors more gracefully. #317

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

Laimiux
Copy link
Collaborator

@Laimiux Laimiux commented Dec 7, 2023

What

Instead of crashing on duplicate child key, we now add an index and notify the global listener to fix the problem. This is better behavior in production than potentially breaking the whole screen.

@@ -18,4 +18,12 @@ object FormulaPlugins {
else -> ListInspector(listOf(global, local))
}
}

fun onDuplicateChildKey(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to generalize this to support other formula errors in the future? So something like:

onError(error: FormulaError)

where FormulaError is a sealed interface

sealed interface FormulaError {
    data class DuplicateKeyError(
        val parentFormulaType: KClass<*>,
        val childFormulaType: KClass<*>,
        val key: Any,
    ) : FormulaError
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe in the future, but for now doesn't seem necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

Any downsides of making it more generic from the start? Would avoid having to make API changes in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Given it's pretty easy to migrate to a different design, I prefer waiting for more than one use case before designing a generic thing.

@Laimiux Laimiux force-pushed the laimonas/handle-duplicate-key-errors branch from 1a3b7af to a4ca1e9 Compare December 7, 2023 23:57
@carrotkite
Copy link

JaCoCo Code Coverage 79.54% ✅

Class Covered Meta Status
com/instacart/formula/internal/FormulaManagerImpl 87% 0%
com/instacart/formula/internal/ChildrenManager 80% 0%
com/instacart/formula/FormulaPlugins 87% 0%

Generated by 🚫 Danger

@Laimiux Laimiux merged commit 3c93bf7 into master Dec 8, 2023
5 checks passed
@Laimiux Laimiux deleted the laimonas/handle-duplicate-key-errors branch December 8, 2023 20:11
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.

4 participants