Skip to content

Commit 1044945

Browse files
authored
fix: use an empty graph if loading failed (#53)
1 parent 1b698a5 commit 1044945

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/types/viewportManager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,14 @@ export function saveToLocalStorage(ctx: GlobalContext) {
225225

226226
export function loadFromLocalStorage(ctx: GlobalContext) {
227227
const jsonData = localStorage.getItem(LOCAL_STORAGE_KEY) || "[]";
228-
const graphData: GraphData = JSON.parse(jsonData);
229-
ctx.load(DataGraph.fromData(graphData));
230-
228+
try {
229+
const graphData: GraphData = JSON.parse(jsonData);
230+
ctx.load(DataGraph.fromData(graphData));
231+
} catch (error) {
232+
const extraData = { jsonData, error };
233+
console.error("Failed to load graph from local storage.", extraData);
234+
ctx.load(new DataGraph());
235+
return;
236+
}
231237
console.log("Graph loaded from local storage.");
232238
}

0 commit comments

Comments
 (0)