smoldot 2.0.37 → 2.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,7 +57,7 @@ function startLocalInstance(config, wasmModule, eventCallback) {
57
57
  eventCallback({ ty: "wasm-panic", message, currentTask: state.currentTask });
58
58
  state.onShutdownExecutorOrWasmPanic();
59
59
  state.onShutdownExecutorOrWasmPanic = () => { };
60
- throw new Error();
60
+ throw new Error("Smoldot has panicked");
61
61
  },
62
62
  chain_initialized: (chainId, errorMsgPtr, errorMsgLen) => {
63
63
  const instance = state.instance;
@@ -313,7 +313,12 @@ function startLocalInstance(config, wasmModule, eventCallback) {
313
313
  const whenReadyAgain = new Promise((resolve) => state.advanceExecutionPromise = () => resolve("ready"));
314
314
  if (!state.instance)
315
315
  break;
316
- state.instance.exports.advance_execution();
316
+ try {
317
+ state.instance.exports.advance_execution();
318
+ }
319
+ catch (_error) {
320
+ return;
321
+ }
317
322
  const afterExec = config.performanceNow();
318
323
  const elapsed = afterExec - now;
319
324
  now = afterExec;
@@ -399,7 +404,15 @@ function startLocalInstance(config, wasmModule, eventCallback) {
399
404
  buffer.writeUInt32LE(potentialRelayChainsEncoded, idx * 4, potentialRelayChains[idx]);
400
405
  }
401
406
  state.bufferIndices[2] = potentialRelayChainsEncoded;
402
- const chainId = state.instance.exports.add_chain(0, 1, disableJsonRpc ? 0 : jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, 2);
407
+ let chainId;
408
+ try {
409
+ chainId = state.instance.exports.add_chain(0, 1, disableJsonRpc ? 0 : jsonRpcMaxPendingRequests, jsonRpcMaxSubscriptions, 2);
410
+ }
411
+ catch (_error) {
412
+ eventCallback({ ty: "add-chain-id-allocated", chainId: 0 });
413
+ eventCallback({ ty: "add-chain-result", chainId: 0, success: false, error: "Smoldot has crashed" });
414
+ return;
415
+ }
403
416
  delete state.bufferIndices[0];
404
417
  delete state.bufferIndices[1];
405
418
  delete state.bufferIndices[2];
@@ -408,7 +421,12 @@ function startLocalInstance(config, wasmModule, eventCallback) {
408
421
  removeChain: (chainId) => {
409
422
  if (!state.instance)
410
423
  return;
411
- state.instance.exports.remove_chain(chainId);
424
+ try {
425
+ state.instance.exports.remove_chain(chainId);
426
+ }
427
+ catch (_error) {
428
+ return;
429
+ }
412
430
  },
413
431
  shutdownExecutor: () => {
414
432
  if (!state.instance)