This issue originates from #3726 (comment) .
Currently, layout visualization errors (specifically related to animations) are handled locally within individual files using defensive checks and console.error. If each of these errors are handled individually in their own way, our error handling will become decentralized, messy, and inconsistent. So, this issue requests that we instead throw errors in the individual files, and catch and handle them upstream in a centralized location.
A possible upstream location to handle layout errors is in CseMachine.redraw(), because that is where Layout.draw() is called. Handling errors there can allow us to render the static diagram of the CSE machine without crashing, should an animation throw an error.
Current situation:
There is one function related to an animation that should be throwing an error, and there could be more in the future.
In CseMachineUtils, there is a function computeFramesCoordChange() that handles logic for the Clear Dead Frames animation. There is a defensive guard:
if (normalizedOldLevels.length !== newLevels.length) {
console.error('Level count mismatch for Clear Dead Frames animation, animation not played.');
}
With the current implementation of the CSE machine, this console.error should never trigger (because of the invariant "oldLevels.length != newLevels.length is always due to deletion of levels with only dead frames"). However, we have added this in case the CSE machine layout is updated to have more complex frame movements (such as frames migrating between levels), which could trigger this error. Using console.error is a temporary solution, and should be changed to throw new Error when centralized error handling is implemented.
This issue originates from #3726 (comment) .
Currently, layout visualization errors (specifically related to animations) are handled locally within individual files using defensive checks and console.error. If each of these errors are handled individually in their own way, our error handling will become decentralized, messy, and inconsistent. So, this issue requests that we instead throw errors in the individual files, and catch and handle them upstream in a centralized location.
A possible upstream location to handle layout errors is in CseMachine.redraw(), because that is where Layout.draw() is called. Handling errors there can allow us to render the static diagram of the CSE machine without crashing, should an animation throw an error.
Current situation:
There is one function related to an animation that should be throwing an error, and there could be more in the future.
In CseMachineUtils, there is a function computeFramesCoordChange() that handles logic for the Clear Dead Frames animation. There is a defensive guard:
With the current implementation of the CSE machine, this console.error should never trigger (because of the invariant "oldLevels.length != newLevels.length is always due to deletion of levels with only dead frames"). However, we have added this in case the CSE machine layout is updated to have more complex frame movements (such as frames migrating between levels), which could trigger this error. Using console.error is a temporary solution, and should be changed to throw new Error when centralized error handling is implemented.