A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
toast an error if Export as png fails (#8049)
Shahmir Varqha0f9238889e9e
diff --git a/frontend/src/utils/__tests__/download.test.tsx b/frontend/src/utils/__tests__/download.test.tsxindex fa011c30fe..4ab19ec0d4 100644--- a/frontend/src/utils/__tests__/download.test.tsx+++ b/frontend/src/utils/__tests__/download.test.tsx@@ -401,13 +401,30 @@ describe("downloadCellOutputAsImage", () => {vi.restoreAllMocks();});- it("should return early if element not found", async () => {+ it("should show error toast if element not found", async () => {await downloadCellOutputAsImage("nonexistent" as CellId, "test");expect(toPng).not.toHaveBeenCalled();expect(Logger.error).toHaveBeenCalledWith("Output element not found for cell nonexistent",);+ expect(toast).toHaveBeenCalledWith({+ title: "Failed to download PNG",+ description: expect.any(String),+ variant: "danger",+ });+ });++ it("should show error toast if toPng fails", async () => {+ vi.mocked(toPng).mockRejectedValue(new Error("Screenshot failed"));++ await downloadCellOutputAsImage("cell-1" as CellId, "result");++ expect(toast).toHaveBeenCalledWith({+ title: "Failed to download PNG",+ description: expect.stringContaining("Screenshot failed"),+ variant: "danger",+ });});it("should download cell output as image", async () => {diff --git a/frontend/src/utils/download.ts b/frontend/src/utils/download.tsindex 17bf39fda0..17451ed035 100644--- a/frontend/src/utils/download.ts+++ b/frontend/src/utils/download.ts@@ -100,11 +100,19 @@ export async function downloadCellOutputAsImage(cellId: CellId,filename: string,) {- const dataUrl = await getImageDataUrlForCell(cellId);- if (!dataUrl) {- return;+ try {+ const dataUrl = await getImageDataUrlForCell(cellId);+ if (!dataUrl) {+ throw new Error("Failed to get image data URL");+ }+ downloadByURL(dataUrl, Filenames.toPNG(filename));+ } catch (error) {+ toast({+ title: "Failed to download PNG",+ description: prettyError(error),+ variant: "danger",+ });}- downloadByURL(dataUrl, Filenames.toPNG(filename));}export const ADD_PRINTING_CLASS = (): (() => void) => {