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
fix: don't show errors in run mode when re-running (#2595)
Myles Scolnick828451aed4d9
diff --git a/frontend/src/components/editor/Cell.tsx b/frontend/src/components/editor/Cell.tsxindex 1d6c08cd6f..af32fc79cd 100644--- a/frontend/src/components/editor/Cell.tsx+++ b/frontend/src/components/editor/Cell.tsx@@ -52,6 +52,7 @@ import type { CellConfig, RuntimeState } from "@/core/network/types";import { MoreHorizontalIcon } from "lucide-react";import { Toolbar, ToolbarItem } from "@/components/editor/cell/toolbar";import { cn } from "@/utils/cn";+import { isErrorMime } from "@/core/mime";/*** Imperative interface of the cell.@@ -417,8 +418,12 @@ const CellComponent = (});if (!editing) {- const hidden = errored || interrupted || stopped;- return hidden ? null : (+ const outputIsError = isErrorMime(output?.mimetype);+ const hidden = errored || interrupted || stopped || outputIsError;+ if (hidden) {+ return null;+ }+ return (<div tabIndex={-1} id={HTMLId} ref={cellRef} className={className}>{outputArea}</div>diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsxindex fa24a153f9..b0fab64b46 100644--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout.tsx@@ -38,6 +38,7 @@ import { FloatingOutline } from "../../chrome/panels/outline/floating-outline";import { KnownQueryParams } from "@/core/constants";import { useUserConfig } from "@/core/config/config";import { MarkdownLanguageAdapter } from "@/core/codemirror/language/markdown";+import { isErrorMime } from "@/core/mime";type VerticalLayout = null;type VerticalLayoutProps = ICellRendererProps<VerticalLayout>;@@ -294,9 +295,13 @@ const VerticalCell = memo();}- const hidden = errored || interrupted || stopped;+ const outputIsError = isErrorMime(output?.mimetype);+ const hidden = errored || interrupted || stopped || outputIsError;+ if (hidden) {+ return null;+ }- return hidden ? null : (+ return (<div tabIndex={-1} id={HTMLId} ref={cellRef} className={className}><OutputAreaallowExpand={mode === "edit"}diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.tsindex cbfce6e831..fb974825ea 100644--- a/frontend/src/core/cells/cells.ts+++ b/frontend/src/core/cells/cells.ts@@ -49,6 +49,7 @@ import {MultiColumn,} from "@/utils/id-tree";import { isEqual } from "lodash-es";+import { isErrorMime } from "../mime";export const SCRATCH_CELL_ID = "__scratch__" as CellId;@@ -1153,7 +1154,7 @@ const cellErrorsAtom = atom((get) => {.map((cellId) => {const cell = cellRuntime[cellId];const { name } = cellData[cellId];- if (cell.output?.mimetype === "application/vnd.marimo+error") {+ if (isErrorMime(cell.output?.mimetype)) {// Filter out ancestor-stopped errors// These are errors that are caused by a cell that was stopped,// but nothing the user can take action on.diff --git a/frontend/src/core/cells/logs.ts b/frontend/src/core/cells/logs.tsindex 82beffb32a..48f4402114 100644--- a/frontend/src/core/cells/logs.ts+++ b/frontend/src/core/cells/logs.ts@@ -3,6 +3,7 @@ import { invariant } from "@/utils/invariant";import type { CellMessage, OutputMessage } from "../kernel/messages";import type { CellId } from "./ids";import { fromUnixTime } from "date-fns";+import { isErrorMime } from "../mime";export interface CellLog {timestamp: number;@@ -13,9 +14,9 @@ export interface CellLog {export function getCellLogsForMessage(cell: CellMessage): CellLog[] {const logs: CellLog[] = [];- const outputs: OutputMessage[] = [cell.console].filter(Boolean).flat();+ const consoleOutputs: OutputMessage[] = [cell.console].filter(Boolean).flat();- for (const output of outputs) {+ for (const output of consoleOutputs) {if (output.mimetype === "text/plain") {invariant(typeof output.data === "string", "expected string");const isError =@@ -40,6 +41,23 @@ export function getCellLogsForMessage(cell: CellMessage): CellLog[] {// Log each to the consolelogs.forEach(CellLogLogger.log);+ // If there is no console output, but there is an error output, let's log that instead+ // This happens in run mode when stderr is not sent to the client.+ if (+ consoleOutputs.length === 0 &&+ isErrorMime(cell.output?.mimetype) &&+ Array.isArray(cell.output.data)+ ) {+ cell.output.data.forEach((error) => {+ CellLogLogger.log({+ level: "stderr",+ cellId: cell.cell_id as CellId,+ timestamp: cell.timestamp,+ message: JSON.stringify(error),+ });+ });+ }+return logs;}diff --git a/frontend/src/core/mime.ts b/frontend/src/core/mime.tsnew file mode 100644index 0000000000..7959e603dd--- /dev/null+++ b/frontend/src/core/mime.ts@@ -0,0 +1,9 @@+/* Copyright 2024 Marimo. All rights reserved. */+import type { OutputMessage } from "./kernel/messages";++export function isErrorMime(mime: OutputMessage["mimetype"] | undefined) {+ return (+ mime === "application/vnd.marimo+error" ||+ mime === "application/vnd.marimo+traceback"+ );+}