MISC: Throw error if tutorial step changed while tutorial is not running - #3090
MISC: Throw error if tutorial step changed while tutorial is not running#3090branchtheory wants to merge 10 commits into
Conversation
|
What do you mean by "changing the tutorial step while the tutorial is not running"? Could you provide MRE (so we can understand and test it better)? |
|
Sure, updated the first comment |
E9cipher
left a comment
There was a problem hiding this comment.
Sounds like a good catch to me! Thanks for explaining :)
|
A question for the boots and cats of the world: In #3079, I've used this pattern a lot: For example:
If we implement this PR though, the only thing the In these specific cases, if this PR gets approved, would you suggest taking the isRunning conditions out? |
|
This is unnecessary, or, to be more precise, it's a solution to a "wrong" issue. How can you increase the tutorial step when the tutorial is not running? If it happens, it's clearly because the tutorial code is buggy. In theory, this would help us catch those bugs, but this is practically useless. Change function iTutorialNextStep(): void {
if (Math.random() < 0.3) {
throw new Error("Tutorial is not running, but iTutorialNextStep() was called");
}
ITutorial.stepIsDone[ITutorial.currStep] = true;
if (ITutorial.currStep < iTutorialSteps.End) {
ITutorial.currStep += 1;
}
if (ITutorial.currStep === iTutorialSteps.End) iTutorialEnd();
ITutorialEvents.emit();
}When you progress through the tutorial, it will simulate a wrong step. However, you will see that the UI does not show that error message. capture.mp4In the worst case, if the thrown error is actually "caught" by something, it's likely the React error boundary, which will activate the recovery screen. This is really bad UX. I'll be frank with you, the tutorial should never have this issue (increase the tutorial step when the tutorial is not running). If it happens, it means either we do not test tutorial code or the tutorial is so unnecessarily complicated that we miss an edge case. The solution is not adding useless checks to |
|
Thanks Catlover. Can you check the commits again? I've updated them with what I think is a better solution. This issue will never happen provided that:
Provided you do that, you don't need these throws at all. You don't even isRunning checks of the kind we do in ScriptEditorRoot: |
|
To be honest, I don't think we need to change anything. This kind of change makes me feel as if we are finding an issue for a solution. You can simplify the condition in some cases, so I'm not exactly against that, but that's unnecessary just to enforce a rule with a comment. Checking In short, there is no need to simplify that check and add a comment explaining when to do so. Just keep things as-is. |
|
OK, that makes sense to me. Thanks for the help. I'll make sure to include isRunning checks in my main Tutorial PR. |
There's currently nothing stopping you incrementing the tutorial step while it's not running. This guards against that to a degree.
Not sure if this is how we generally solve this problem?
EDIT: OK here's what's going on.
When you start the tutorial, that switches an isRunning flag in ITutorial (in InteractiveTutorial.ts) to
true, and sets your current tutorial step to Start.You can then increment / decrement the tutorial step with iTutorialNextStep() and iTutorialPrevStep().
When you hit the last step of the tutorial, that triggers iTutorialEnd(), which switches isRunning to
false, and resets the tutorial step to Start as well.The problem this PR would mitigate is that there's currently no check on calling iTutorialNextStep() or iTutorialPrevStep(). You can call them any time you like, even if the tutorial isn't running.
Having this throw an error would help you spot your mistake.