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

More unique Exceptions #714

Open
DatL4g opened this issue Jul 15, 2024 · 3 comments
Open

More unique Exceptions #714

DatL4g opened this issue Jul 15, 2024 · 3 comments

Comments

@DatL4g
Copy link

DatL4g commented Jul 15, 2024

Please separate your exceptions more uniquely as there is no way of operating special use-cases.

Functions throwing a IllegalStateException:

  • spec (2x)
  • dispatch
  • checkSpecBlockSet

Maybe create something like this?
Didn't create PR as I'm not sure how you want to adopt things, but here a simple example:

sealed interface FlowReduxException {
	data object AlreadyInitialized : IllegalStateException(
                "State machine spec has already been set. " +
                    "It's only allowed to call spec {...} once.",
            ), FlowReduxException

	data object AlreadyCollected : IllegalStateException(
                        "Can not collect state more than once at the same time. Make sure the" +
                            "previous collection is cancelled before starting a new one. " +
                            "Collecting state in parallel would lead to subtle bugs.",
                    ), FlowReduxException

	data object NotInitialized : IllegalStateException(
                """
                    No state machine specs are defined. Did you call spec { ... } in init {...}?
                    Example usage:

                    class MyStateMachine : FlowReduxStateMachine<State, Action>(InitialState) {

                        init{
                            spec {
                                inState<FooState> {
                                    on<BarAction> { ... }
                                }
                                ...
                            }
                        }
                    }
                """.trimIndent(),
            ), FlowReduxException

	data class NotCollected(val action: A) : IllegalStateException(
                "Cannot dispatch action $action because state Flow of this " +
                    "FlowReduxStateMachine is not collected yet. " +
                    "Start collecting the state Flow before dispatching any action.",
            ), FlowReduxException
}
@gabrielittner
Copy link
Member

as there is no way of operating special use-cases

Could you expand on what these cases are and what you need to handle?

@DatL4g
Copy link
Author

DatL4g commented Jul 25, 2024

I would want to ignore NotCollected exceptions and not all IllegalStateException FlowRedux throws.

Sure that's pretty easy as it's only thrown in dispatch but it's way easier to keep track of it in the code then.

Additionally Firebase Crashlytics for example summarize exceptions and send reports per mail.
However this mails just show that it's a IllegalStateException, not where it's thrown.

Overall it just improves code and crash report readability

@gabrielittner
Copy link
Member

Makes sense 👍 I'll add something soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants