Skip to content

More unique Exceptions #714

Open
Open
@DatL4g

Description

@DatL4g

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions