feat: surface error when dropping wasm node

This commit is contained in:
2026-05-07 21:10:31 +02:00
parent bd6dfeb466
commit 7d788f7e19
@@ -1,3 +1,4 @@
import { toast } from '@nodarium/ui';
import { GraphSchema, type NodeId } from '@nodarium/types'; import { GraphSchema, type NodeId } from '@nodarium/types';
import type { GraphManager } from '../graph-manager.svelte'; import type { GraphManager } from '../graph-manager.svelte';
import type { GraphState } from '../graph-state.svelte'; import type { GraphState } from '../graph-state.svelte';
@@ -41,6 +42,9 @@ export class FileDropEventManager {
props, props,
position: pos position: pos
}); });
}).catch((e) => {
toast(`Failed to load node: ${nodeId}`, 'error');
console.error(e);
}); });
} else if (event.dataTransfer.files.length) { } else if (event.dataTransfer.files.length) {
const file = event.dataTransfer.files[0]; const file = event.dataTransfer.files[0];
@@ -65,8 +69,13 @@ export class FileDropEventManager {
reader.onload = (e) => { reader.onload = (e) => {
const buffer = e.target?.result as ArrayBuffer; const buffer = e.target?.result as ArrayBuffer;
if (buffer) { if (buffer) {
try {
const state = GraphSchema.parse(JSON.parse(buffer.toString())); const state = GraphSchema.parse(JSON.parse(buffer.toString()));
this.graph.load(state); this.graph.load(state);
} catch (e) {
toast('Failed to load graph: invalid file', 'error');
console.error(e);
}
} }
}; };
reader.readAsText(file); reader.readAsText(file);