Skip to content

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.

feature: Errors sidebar (#193)

Myles Scolnick6c45ca685e16
diff --git a/frontend/src/core/state/cells.ts b/frontend/src/core/state/cells.ts
index cf2192686e..92be3b515c 100644
--- a/frontend/src/core/state/cells.ts
+++ b/frontend/src/core/state/cells.ts
@@ -410,6 +410,22 @@ export const getAllEditorViews = () => {
.flatMap((x) => (x ? [x] : []));
};
+export const cellErrors = atom((get) => {
+ const errors = get(cellsAtom)
+ .present.map((cell) =>
+ cell.output?.mimetype === "application/vnd.marimo+error"
+ ? {
+ output: cell.output,
+ cellId: cell.key,
+ }
+ : null
+ )
+ .filter(Boolean);
+ return errors;
+});
+
+export const cellErrorCount = atom((get) => get(cellErrors).length);
+
/**
* Use this hook to dispatch cell actions. This hook will not cause a re-render
* when cells change.
diff --git a/frontend/src/editor/chrome/panels/error-panel.tsx b/frontend/src/editor/chrome/panels/error-panel.tsx
index 9a45a3f1ab..0f1141cf99 100644
--- a/frontend/src/editor/chrome/panels/error-panel.tsx
+++ b/frontend/src/editor/chrome/panels/error-panel.tsx
@@ -1,25 +1,36 @@
/* Copyright 2023 Marimo. All rights reserved. */
import React from "react";
-import { useCells } from "../../../core/state/cells";
+import { cellErrors } from "../../../core/state/cells";
import { MarimoErrorOutput } from "../../output/MarimoErrorOutput";
+import { CellLinkError } from "@/editor/links/cell-link";
+import { useAtomValue } from "jotai";
+import { PartyPopperIcon } from "lucide-react";
+
+export const ErrorsPanel: React.FC = () => {
+ const errors = useAtomValue(cellErrors);
+
+ if (errors.length === 0) {
+ return (
+ <div className="mx-6 my-6 flex flex-row gap-2 items-center rounded-lg">
+ <PartyPopperIcon className="text-accent-foreground" />
+ <span className="mt-[0.25rem] text-accent-foreground">
+ {" "}
+ No errors!{" "}
+ </span>
+ </div>
+ );
+ }
-export const ErrorsPanel: React.FC = (props) => {
- const cells = useCells();
- const errors = cells.present
- .map((cell) =>
- cell.output?.mimetype === "application/vnd.marimo+error"
- ? {
- output: cell.output,
- cellId: cell.key,
- }
- : null
- )
- .filter(Boolean);
return (
- <div className="flex flex-col gap-3 px-2">
+ <div className="flex flex-col overflow-auto">
{errors.map((error) => (
<div key={error.cellId}>
- <MarimoErrorOutput key={error.cellId} errors={error.output.data} />
+ <div className="text-xs font-mono font-semibold bg-muted border-y px-2 py-1">
+ <CellLinkError cellId={error.cellId} />
+ </div>
+ <div key={error.cellId} className="px-2">
+ <MarimoErrorOutput key={error.cellId} errors={error.output.data} />
+ </div>
</div>
))}
</div>
diff --git a/frontend/src/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/editor/chrome/wrapper/app-chrome.tsx
index 0d3a942b56..8479c0213f 100644
--- a/frontend/src/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/editor/chrome/wrapper/app-chrome.tsx
@@ -16,6 +16,7 @@ import { useVariables } from "@/core/variables/state";
import { useCellIds } from "@/core/state/cells";
import { Button } from "@/components/ui/button";
import { XIcon } from "lucide-react";
+import { ErrorsPanel } from "../panels/error-panel";
export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
const { isOpen, selectedPanel, panelLocation } = useChromeState();
@@ -55,11 +56,11 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
/>
);
- const variablePane = (
- <div className="flex flex-col h-full flex-1 overflow-hidden">
+ const helpPaneBody = (
+ <div className="flex flex-col h-full flex-1 overflow-hidden mr-[-4px]">
<div className="p-3 border-b flex justify-between items-center">
<div className="text-sm text-[var(--slate-11)] uppercase tracking-wide font-semibold flex-1">
- Variables
+ {selectedPanel}
</div>
<Button
className="m-0"
@@ -70,7 +71,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
<XIcon className="w-4 h-4" />
</Button>
</div>
- {/* {selectedPanel === "errors" && <ErrorsPanel />} */}
+ {selectedPanel === "errors" && <ErrorsPanel />}
{selectedPanel === "variables" && (
<VariableTable
className="flex-1"
@@ -107,11 +108,11 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
>
{panelLocation === "left" ? (
<span className="flex flex-row h-full">
- {variablePane} {resizeHandle}
+ {helpPaneBody} {resizeHandle}
</span>
) : (
<span>
- {resizeHandle} {variablePane}
+ {resizeHandle} {helpPaneBody}
</span>
)}
</Panel>
diff --git a/frontend/src/editor/chrome/wrapper/footer.tsx b/frontend/src/editor/chrome/wrapper/footer.tsx
index b35de21d91..bef17589a4 100644
--- a/frontend/src/editor/chrome/wrapper/footer.tsx
+++ b/frontend/src/editor/chrome/wrapper/footer.tsx
@@ -1,33 +1,42 @@
/* Copyright 2023 Marimo. All rights reserved. */
import React, { PropsWithChildren } from "react";
-import { PanelBottomIcon, PanelLeftIcon, VariableIcon } from "lucide-react";
+import {
+ PanelBottomIcon,
+ PanelLeftIcon,
+ CircleEqualIcon,
+ XCircleIcon,
+} from "lucide-react";
import { cn } from "@/lib/utils";
import { useChromeActions, useChromeState } from "../state";
import { Tooltip } from "@/components/ui/tooltip";
+import { useAtomValue } from "jotai";
+import { cellErrorCount } from "@/core/state/cells";
export const Footer: React.FC = () => {
const { selectedPanel, panelLocation } = useChromeState();
const { openApplication, changePanelLocation } = useChromeActions();
+ const errorCount = useAtomValue(cellErrorCount);
return (
- <footer className="h-10 py-2 bg-background flex items-center text-muted-foreground text-md px-6 border-t border-border select-none no-print">
- {/* <FooterItem
+ <footer className="h-10 py-2 bg-background flex items-center text-muted-foreground text-md px-6 border-t border-border select-none no-print text-sm">
+ <FooterItem
+ tooltip="View errors"
selected={selectedPanel === "errors"}
onClick={() => openApplication("errors")}
>
<XCircleIcon
className={cn("h-4 w-4 mr-1", {
- "text-destructive": errors.length > 0,
+ "text-destructive": errorCount > 0,
})}
/>
- {errors.length}
- </FooterItem> */}
+ <span className="font-mono mt-[0.125rem]">{errorCount}</span>
+ </FooterItem>
<FooterItem
tooltip="Explore variables"
selected={selectedPanel === "variables"}
onClick={() => openApplication("variables")}
>
- <VariableIcon className={cn("h-4 w-4")} />
+ <CircleEqualIcon className={cn("h-4 w-4")} />
</FooterItem>
<div className="mx-auto" />
<FooterItem
diff --git a/frontend/src/editor/links/cell-link.tsx b/frontend/src/editor/links/cell-link.tsx
index 9c58c0b72f..58279906c9 100644
--- a/frontend/src/editor/links/cell-link.tsx
+++ b/frontend/src/editor/links/cell-link.tsx
@@ -9,7 +9,7 @@ interface Props {
variant?: "destructive" | "focus";
}
-/* Component that adds a link to a cell, for use in a MarimoError. */
+/* Component that adds a link to a cell, with styling. */
export const CellLink = (props: Props): JSX.Element => {
const { className, cellId, variant } = props;
const cellName = HTMLCellId.create(cellId);
@@ -50,3 +50,13 @@ export const CellLink = (props: Props): JSX.Element => {
</div>
);
};
+
+/* Component that adds a link to a cell, for use in a MarimoError. */
+export const CellLinkError = (
+ props: Pick<Props, "className" | "cellId">
+): JSX.Element => {
+ const { className, cellId } = props;
+ return (
+ <CellLink className={className} cellId={cellId} variant={"destructive"} />
+ );
+};
diff --git a/frontend/src/editor/output/MarimoErrorOutput.tsx b/frontend/src/editor/output/MarimoErrorOutput.tsx
index 2365193aa8..3414ca24d8 100644
--- a/frontend/src/editor/output/MarimoErrorOutput.tsx
+++ b/frontend/src/editor/output/MarimoErrorOutput.tsx
@@ -13,7 +13,7 @@ import {
AccordionTrigger,
} from "@/components/ui/accordion";
import { Fragment } from "react";
-import { CellLink } from "../links/cell-link";
+import { CellLinkError } from "../links/cell-link";
const Tip = (props: {
className?: string;
@@ -65,9 +65,9 @@ export const MarimoErrorOutput = ({
<ul className="list-disc">
{error.edges.map((edge) => (
<li className={liStyle} key={`${edge[0]}-${edge[1]}`}>
- <CellLink cellId={edge[0]} />
+ <CellLinkError cellId={edge[0]} />
{" -> "}
- <CellLink cellId={edge[1]} />
+ <CellLinkError cellId={edge[1]} />
</li>
))}
</ul>
@@ -84,7 +84,7 @@ export const MarimoErrorOutput = ({
<ul className="list-disc">
{error.cells.map((cid) => (
<li className={liStyle} key={cid}>
- <CellLink cellId={cid} />
+ <CellLinkError cellId={cid} />
</li>
))}
</ul>
@@ -102,7 +102,7 @@ export const MarimoErrorOutput = ({
<p className="mt-4">
{`The variable '${error.name}' can't be deleted because it was defined by another cell ` +
`(`}
- <CellLink cellId={error.cells[0]} />
+ <CellLinkError cellId={error.cells[0]} />
{")"}
</p>
<Tip>
@@ -128,9 +128,9 @@ export const MarimoErrorOutput = ({
) : (
<p key={idx}>
{error.msg}
- <CellLink cellId={error.raising_cell} />
+ <CellLinkError cellId={error.raising_cell} />
<Tip>
- Fix the error in <CellLink cellId={error.raising_cell} />, or
+ Fix the error in <CellLinkError cellId={error.raising_cell} />, or
handle the exception in with a try/except block.
</Tip>
</p>
@@ -142,7 +142,7 @@ export const MarimoErrorOutput = ({
return (
<p key={idx}>
{error.msg}
- <CellLink cellId={error.raising_cell} />
+ <CellLinkError cellId={error.raising_cell} />
</p>
);