Handle missing selected workspace files

This commit is contained in:
Federico Jaramillo Martinez
2026-05-11 10:41:33 +02:00
parent 1ae43998e7
commit 045f4e247a
4 changed files with 24 additions and 2 deletions
@@ -50,13 +50,26 @@ export class FileExplorerController {
if (project === undefined || workspace === undefined) return;
this.setState({ selectedFilePath: path, selectedFileContent: undefined });
try {
this.setState({ selectedFileContent: await api.workspaceFile(project.id, workspace.id, path), error: "" });
const content = await api.workspaceFile(project.id, workspace.id, path);
if (this.getState().selectedFilePath === path) this.setState({ selectedFileContent: content, error: "" });
} catch (error) {
if (this.getState().selectedFilePath !== path) return;
if (isUnavailableFileError(error)) {
this.setState({ selectedFilePath: undefined, selectedFileContent: undefined, error: "" });
setNamespacedQueryKey(FILES_ROUTE_NAMESPACE, "file", undefined, { replace: true });
this.updateUrl({ replace: true });
return;
}
this.setState({ error: String(error) });
}
}
}
function isUnavailableFileError(error: unknown): boolean {
const message = String(error);
return message.includes("Path does not exist") || message.includes("ENOENT") || message.includes("no such file or directory");
}
function omitKey<T>(record: Record<string, T>, keyToOmit: string): Record<string, T> {
return Object.fromEntries(Object.entries(record).filter(([key]) => key !== keyToOmit));
}