Skip to content

Commit dd9cf49

Browse files
authored
Hotfix notebook (#789)
1 parent 8a8bbc8 commit dd9cf49

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/app/app/virtual-lab/lab/[virtualLabId]/project/[projectId]/(pages)/notebooks/member/UserNotebookPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ export default function UserNotebookPage({
6262
);
6363
const [loading, setLoading] = useDelayedLoading(false);
6464
const [deleteNotebookId, setDeleteNotebookId] = useState('');
65+
const errorShown = useRef(false);
6566

66-
if (serverError)
67+
if (serverError !== '' && !errorShown.current) {
6768
notification.error({
6869
message: serverError,
6970
key: 'user-notebook-server-error',
7071
placement: 'topRight',
7172
});
73+
errorShown.current = true;
74+
}
7275

7376
const resetModal = () => {
7477
setOpenModal(false);
@@ -257,7 +260,7 @@ export default function UserNotebookPage({
257260
} catch (e) {
258261
notification.error({
259262
message: assertErrorMessage(e),
260-
key: 'user-notebook-server-error',
263+
key: 'user-notebook-register-error',
261264
placement: 'topRight',
262265
});
263266
resetModal();

src/app/app/virtual-lab/lab/[virtualLabId]/project/[projectId]/(pages)/notebooks/member/page.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default async function Notebooks({
1313
}: ServerSideComponentProp<{ projectId: string; virtualLabId: string }, any>) {
1414
const params = await promisedParams;
1515
const { projectId, virtualLabId } = params;
16-
let error = '';
16+
let warning = '';
1717
let initialNotebooks: Notebook[] = [];
1818

1919
try {
@@ -25,22 +25,29 @@ export default async function Notebooks({
2525

2626
const notebooks = NotebooksArraySchema.parse(userNotebookData.data.results);
2727

28-
const notebooksPromises = notebooks.map((n) => fetchNotebook(n.github_file_url));
28+
const notebooksPromises = notebooks.map(async (n) => {
29+
try {
30+
const notebookData = await fetchNotebook(n.github_file_url);
31+
return { ...notebookData, id: n.id, creationDate: n.created_at };
32+
} catch (e) {
33+
// Collect warning but continue
34+
warning = `The notebook ${n.github_file_url} failed to load, please ensure the notebook folder exists and the repository is public`;
35+
return null; // skip this notebook
36+
}
37+
});
2938

3039
const validatedNotebooks = await Promise.all(notebooksPromises);
31-
initialNotebooks = validatedNotebooks.map((n, i) => {
32-
return { ...n, id: notebooks[i].id, creationDate: notebooks[i].created_at };
33-
});
40+
initialNotebooks = validatedNotebooks.filter(Boolean) as Notebook[];
3441
} catch (e) {
35-
error = assertErrorMessage(e);
42+
warning = assertErrorMessage(e); // fail only if the main list fetch fails
3643
}
3744

3845
return (
3946
<UserNotebookPage
4047
initialNotebooks={initialNotebooks}
4148
projectId={projectId}
4249
vlabId={virtualLabId}
43-
serverError={error}
50+
serverError={warning}
4451
/>
4552
);
4653
}

src/util/virtual-lab/fetchNotebooks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export default async function fetchNotebooks(repoUrl: string, withDate = false)
5454
return acc;
5555
}, {});
5656

57+
let error = '';
58+
5759
for (const item of Object.values(items)) {
5860
if (item.path.endsWith('analysis_notebook.ipynb')) {
5961
if (withDate)
@@ -85,9 +87,7 @@ export default async function fetchNotebooks(repoUrl: string, withDate = false)
8587
objectOfInterest: metadata.input.flatMap((i) => i.data_type.artefact).join(', '),
8688
});
8789
} catch (e) {
88-
throw new Error(
89-
`Error fetching or validating metadata for notebook ${repoUrl} ${item.path} \n ${e}`
90-
);
90+
error = `Error fetching or validating metadata for notebook ${repoUrl} ${item.path} \n ${e}`;
9191
}
9292
}
9393
}
@@ -102,7 +102,7 @@ export default async function fetchNotebooks(repoUrl: string, withDate = false)
102102
n.creationDate = dates[i];
103103
return n;
104104
}),
105-
error: '',
105+
error,
106106
};
107107
} catch (e) {
108108
return { notebooks: [], error: assertErrorMessage(e) };

0 commit comments

Comments
 (0)