final void transitionTo(final Task.State newState) {
        final State oldState = state();
        if (oldState.isValidTransition(newState)) {
            state = newState;
            stateMgr.transitionTaskState(newState);
        } else {
            throw new IllegalStateException("Invalid transition from " + oldState + " to " + newState);
        }
    }
The following exceptions maybe thrown from the state manager flushing call

@throws TaskMigratedException recoverable error sending changelog records that would cause the task to be removed
@throws StreamsException fatal error when flushing the state store, for example sending changelog records failed
                         or flushing state store get IO errors; such error should cause the thread to die
streams/src/main/java/org/apache/kafka/streams/processor/internals/AbstractTask.java