Fix: clearSceneAndBustCache when rust panics because it can load a stale cache (#6809)
* fix: clear scene and bust cache if rust panics * fix: pr clean up * fix: huh? cargo fmt doesn't do this?
This commit is contained in:
@ -426,6 +426,7 @@ export class KclManager {
|
|||||||
EXECUTE_AST_INTERRUPT_ERROR_MESSAGE
|
EXECUTE_AST_INTERRUPT_ERROR_MESSAGE
|
||||||
)
|
)
|
||||||
// Exit early if we are already executing.
|
// Exit early if we are already executing.
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,6 +438,7 @@ export class KclManager {
|
|||||||
|
|
||||||
this.isExecuting = true
|
this.isExecuting = true
|
||||||
await this.ensureWasmInit()
|
await this.ensureWasmInit()
|
||||||
|
|
||||||
const { logs, errors, execState, isInterrupted } = await executeAst({
|
const { logs, errors, execState, isInterrupted } = await executeAst({
|
||||||
ast,
|
ast,
|
||||||
path: this.singletons.codeManager.currentFilePath || undefined,
|
path: this.singletons.codeManager.currentFilePath || undefined,
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
|
|
||||||
import { kclManager } from '@src/lib/singletons'
|
import { kclManager, rustContext } from '@src/lib/singletons'
|
||||||
import { reportRejection } from '@src/lib/trap'
|
import { reportRejection } from '@src/lib/trap'
|
||||||
import { getModule, reloadModule } from '@src/lib/wasm_lib_wrapper'
|
import { getModule, reloadModule } from '@src/lib/wasm_lib_wrapper'
|
||||||
|
import { jsAppSettings } from '@src/lib/settings/settingsUtils'
|
||||||
|
|
||||||
let initialized = false
|
let initialized = false
|
||||||
|
|
||||||
@ -16,7 +17,11 @@ export const initializeWindowExceptionHandler = () => {
|
|||||||
if (window && !initialized) {
|
if (window && !initialized) {
|
||||||
window.addEventListener('error', (event) => {
|
window.addEventListener('error', (event) => {
|
||||||
void (async () => {
|
void (async () => {
|
||||||
if (matchImportExportErrorCrash(event.message)) {
|
if (
|
||||||
|
matchImportExportErrorCrash(event.message) ||
|
||||||
|
matchUnreachableErrorCrash(event.message) ||
|
||||||
|
matchGenericWasmRuntimeHeuristicErrorCrash(event)
|
||||||
|
) {
|
||||||
// do global singleton cleanup
|
// do global singleton cleanup
|
||||||
kclManager.executeAstCleanUp()
|
kclManager.executeAstCleanUp()
|
||||||
toast.error(
|
toast.error(
|
||||||
@ -25,6 +30,19 @@ export const initializeWindowExceptionHandler = () => {
|
|||||||
try {
|
try {
|
||||||
await reloadModule()
|
await reloadModule()
|
||||||
await getModule().default()
|
await getModule().default()
|
||||||
|
/**
|
||||||
|
* If I do not cache bust, swapping between files when a rust runtime error happens
|
||||||
|
* it will cache the result of the crashed result and not re executing a new good file
|
||||||
|
* CacheResult::NoAction(false) => {
|
||||||
|
* let outcome = old_state.to_exec_outcome(result_env).await;
|
||||||
|
* return Ok(outcome);
|
||||||
|
* }
|
||||||
|
* ^-- this is the block of code that returns which prevents it from running a new execute
|
||||||
|
*/
|
||||||
|
await rustContext?.clearSceneAndBustCache(
|
||||||
|
await jsAppSettings(),
|
||||||
|
undefined
|
||||||
|
)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to initialize wasm_lib')
|
console.error('Failed to initialize wasm_lib')
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@ -50,3 +68,20 @@ const matchImportExportErrorCrash = (message: string): boolean => {
|
|||||||
const substringError = '`Result::unwrap_throw()` on an `Err` value'
|
const substringError = '`Result::unwrap_throw()` on an `Err` value'
|
||||||
return message.indexOf(substringError) !== -1 ? true : false
|
return message.indexOf(substringError) !== -1 ? true : false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const matchUnreachableErrorCrash = (message: string): boolean => {
|
||||||
|
const substringError = `Uncaught RuntimeError: unreachable`
|
||||||
|
return message.indexOf(substringError) !== -1 ? true : false
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchGenericWasmRuntimeHeuristicErrorCrash = (
|
||||||
|
error: ErrorEvent
|
||||||
|
): boolean => {
|
||||||
|
const stack = error?.error?.stack || null
|
||||||
|
if (typeof stack === 'string') {
|
||||||
|
const substringError = `WebAssembly.instantiate:wasm-function`
|
||||||
|
return stack.indexOf(substringError) !== -1 ? true : false
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user