feat: surface error when dropping wasm node
This commit is contained in:
@@ -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) {
|
||||||
const state = GraphSchema.parse(JSON.parse(buffer.toString()));
|
try {
|
||||||
this.graph.load(state);
|
const state = GraphSchema.parse(JSON.parse(buffer.toString()));
|
||||||
|
this.graph.load(state);
|
||||||
|
} catch (e) {
|
||||||
|
toast('Failed to load graph: invalid file', 'error');
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user