Skip to content

Commit 1f43020

Browse files
authored
Stat File Error Overlay and Clear Errors on Connection Change (#1997)
This adds two small features: - if a backend file stat operation fails, an error overlay is shown on the frontend - for all frontend error overlays, if the connection changes, the error is cleared
1 parent 2df1c2e commit 1f43020

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

frontend/app/view/preview/preview.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,20 @@ export class PreviewModel implements ViewModel {
388388
if (fileName == null) {
389389
return null;
390390
}
391-
const statFile = await RpcApi.FileInfoCommand(TabRpcClient, {
392-
info: {
393-
path,
394-
},
395-
});
396-
console.log("stat file", statFile);
397-
return statFile;
391+
try {
392+
const statFile = await RpcApi.FileInfoCommand(TabRpcClient, {
393+
info: {
394+
path,
395+
},
396+
});
397+
return statFile;
398+
} catch (e) {
399+
const errorStatus: ErrorMsg = {
400+
status: "File Read Failed",
401+
text: `${e}`,
402+
};
403+
globalStore.set(this.errorMsgAtom, errorStatus);
404+
}
398405
});
399406
this.fileMimeType = atom<Promise<string>>(async (get) => {
400407
const fileInfo = await get(this.statFile);
@@ -410,21 +417,20 @@ export class PreviewModel implements ViewModel {
410417
if (fileName == null) {
411418
return null;
412419
}
413-
let file: FileData;
414420
try {
415-
file = await RpcApi.FileReadCommand(TabRpcClient, {
421+
const file = await RpcApi.FileReadCommand(TabRpcClient, {
416422
info: {
417423
path,
418424
},
419425
});
426+
return file;
420427
} catch (e) {
421428
const errorStatus: ErrorMsg = {
422429
status: "File Read Failed",
423430
text: `${e}`,
424431
};
425432
globalStore.set(this.errorMsgAtom, errorStatus);
426433
}
427-
return file;
428434
});
429435

430436
this.fileContentSaved = atom(null) as PrimitiveAtom<string | null>;
@@ -1064,6 +1070,12 @@ function PreviewView({
10641070
}) {
10651071
const connStatus = useAtomValue(model.connStatus);
10661072
const [errorMsg, setErrorMsg] = useAtom(model.errorMsgAtom);
1073+
const connection = useAtomValue(model.connectionImmediate);
1074+
1075+
useEffect(() => {
1076+
setErrorMsg(null);
1077+
}, [connection]);
1078+
10671079
if (connStatus?.status != "connected") {
10681080
return null;
10691081
}
@@ -1089,6 +1101,7 @@ function PreviewView({
10891101
const fetchSuggestionsFn = async (query, ctx) => {
10901102
return await fetchSuggestions(model, query, ctx);
10911103
};
1104+
10921105
return (
10931106
<>
10941107
{/* <OpenFileModal blockId={blockId} model={model} blockRef={blockRef} /> */}

0 commit comments

Comments
 (0)