Skip to content

Commit 26dfc53

Browse files
committed
feat(runtime): add silent option to openWorkspaceHdf5 to control error logging
1 parent 1b9700a commit 26dfc53

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎src/App.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,9 @@ export default function App() {
21342134
try {
21352135
const bytes = new Uint8Array(await file.arrayBuffer());
21362136
try {
2137-
await runtime.openWorkspaceHdf5(file.name, bytes, true);
2137+
await runtime.openWorkspaceHdf5(file.name, bytes, true, {
2138+
silent: true,
2139+
});
21382140
} catch (err) {
21392141
const msg = err instanceof Error ? err.message : String(err);
21402142
// Qt parity: when the file is a regular HDF5 file (not a

‎src/runtime/runtime.ts‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,9 @@ await micropip.install(["sigima", "guidata"])
10841084
}
10851085
return value;
10861086
} catch (err) {
1087-
console.error(`[runtime] ${name} failed`, err);
1087+
if (!options.silent) {
1088+
console.error(`[runtime] ${name} failed`, err);
1089+
}
10881090
throw err;
10891091
} finally {
10901092
fn.destroy?.();
@@ -1587,17 +1589,27 @@ await micropip.install(["sigima", "guidata"])
15871589
}
15881590

15891591
/** Load *bytes* (a DataLab-compatible HDF5 workspace) into the model.
1590-
* When *replace* is true (default), the current model is wiped first. */
1592+
* When *replace* is true (default), the current model is wiped first.
1593+
*
1594+
* Pass ``silent: true`` when the caller probes whether a file is a
1595+
* workspace and intends to fall back to plain HDF5 import; in that
1596+
* case the expected ``Not a DataLab HDF5 workspace`` Python error
1597+
* should not be logged as a runtime error. */
15911598
async openWorkspaceHdf5(
15921599
filename: string,
15931600
bytes: Uint8Array,
15941601
replace: boolean = true,
1602+
options: { silent?: boolean } = {},
15951603
): Promise<WorkspaceLoadResult> {
1596-
return (await this.callPy("open_workspace_from_bytes", {
1597-
filename,
1598-
data: bytes,
1599-
replace,
1600-
})) as WorkspaceLoadResult;
1604+
return (await this.callPy(
1605+
"open_workspace_from_bytes",
1606+
{
1607+
filename,
1608+
data: bytes,
1609+
replace,
1610+
},
1611+
{ silent: options.silent },
1612+
)) as WorkspaceLoadResult;
16011613
}
16021614

16031615
// ------------------------------------------------------------------

0 commit comments

Comments
 (0)