Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict Execution #1580

Merged
merged 24 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions frontend/src/components/editor/output/MarimoErrorOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,37 @@ export const MarimoErrorOutput = ({
</Tip>
</div>
);
case "strict-exception":
return error.blamed_cell == null ? (
<Fragment key={idx}>
<p>{error.msg}</p>
<Tip>
Something is wrong with your declaration of {error.ref}. Fix any
discrepancies, or turn off strict execution.
</Tip>
</Fragment>
) : (
<div key={idx}>
{error.msg}
<CellLinkError cellId={error.blamed_cell} />
<Tip>
Ensure that <CellLinkError cellId={error.blamed_cell} />
defines the variable {error.ref}, or turn off strict execution.
</Tip>
</div>
);
case "ancestor-prevented":
titleContents = "Ancestor prevented from running";
alertVariant = "default";
textColor = "text-secondary-foreground";
return (
<div key={idx}>
{error.msg}
(<CellLinkError cellId={error.raising_cell} />
blames
<CellLinkError cellId={error.blamed_cell} />)
</div>
);
case "ancestor-stopped":
titleContents = "Ancestor stopped";
alertVariant = "default";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/core/cells/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function transitionCell(
nextCell.interrupted = true;
didInterruptFromThisMessage = true;
} else if (
message.output.data.some((error) => error.type === "ancestor-stopped")
message.output.data.some((error) => error.type.includes("ancestor"))
) {
// The cell didn't run, but it was intentional, so don't count as
// errored.
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/core/cells/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ const cellErrorsAtom = atom((get) => {
// These are errors that are caused by a cell that was stopped,
// but nothing the user can take action on.
const nonAncestorErrors = cell.output.data.filter(
(error) => error.type !== "ancestor-stopped",
(error) => !error.type.includes("ancestor"),
);

if (nonAncestorErrors.length > 0) {
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/core/kernel/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ export type MarimoError =
msg: string;
raising_cell?: CellId;
}
| {
type: "ancestor-prevented";
msg: string;
raising_cell: CellId;
blamed_cell: CellId;
}
| { type: "ancestor-stopped"; msg: string; raising_cell: CellId }
| { type: "cycle"; edges_with_vars: Array<[CellId, string[], CellId]> }
| { type: "multiple-defs"; name: string; cells: CellId[] }
| { type: "delete-nonlocal"; name: string; cells: CellId[] }
| {
type: "strict-exception";
msg: string;
ref: string;
blamed_cell: CellId;
}
| { type: "unknown"; msg?: string };

export type OutputMessage =
Expand Down
12 changes: 8 additions & 4 deletions marimo/_ast/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
Cell,
CellConfig,
CellId_t,
execute_cell,
execute_cell_async,
)
from marimo._ast.compiler import cell_factory
from marimo._ast.errors import (
Expand All @@ -36,6 +34,10 @@
from marimo._messaging.types import NoopStream
from marimo._output.rich_help import mddoc
from marimo._runtime import dataflow
from marimo._runtime.executor import (
execute_cell,
execute_cell_async,
)
from marimo._runtime.patches import patch_main_module_context

if TYPE_CHECKING:
Expand Down Expand Up @@ -271,7 +273,7 @@ def _run_sync(
self._execution_context = ExecutionContext(
cell_id=cid, setting_element_value=False
)
outputs[cid] = execute_cell(cell._cell, glbls)
outputs[cid] = execute_cell(cell._cell, glbls, self._graph)
for hook in post_execute_hooks:
hook()
return self._outputs_and_defs(outputs, glbls)
Expand All @@ -293,7 +295,9 @@ async def _run_async(
self._execution_context = ExecutionContext(
cell_id=cid, setting_element_value=False
)
outputs[cid] = await execute_cell_async(cell._cell, glbls)
outputs[cid] = await execute_cell_async(
cell._cell, glbls, self._graph
)
for hook in post_execute_hooks:
hook()
self._execution_context = None
Expand Down
24 changes: 0 additions & 24 deletions marimo/_ast/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,27 +434,3 @@ def __call__(self, *args: Any, **kwargs: Any) -> None:

def is_ws(char: str) -> bool:
return char == " " or char == "\n" or char == "\t"


async def execute_cell_async(cell: CellImpl, glbls: dict[Any, Any]) -> Any:
if cell.body is None:
return None
assert cell.last_expr is not None

if _is_coroutine(cell.body):
await eval(cell.body, glbls)
else:
exec(cell.body, glbls)

if _is_coroutine(cell.last_expr):
return await eval(cell.last_expr, glbls)
else:
return eval(cell.last_expr, glbls)


def execute_cell(cell: CellImpl, glbls: dict[Any, Any]) -> Any:
if cell.body is None:
return None
assert cell.last_expr is not None
exec(cell.body, glbls)
return eval(cell.last_expr, glbls)
3 changes: 2 additions & 1 deletion marimo/_ast/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
CellId_t,
CellImpl,
)
from marimo._ast.visitor import ScopedVisitor, is_local
from marimo._ast.visitor import ScopedVisitor
from marimo._utils.tmpdir import get_tmpdir
from marimo._utils.variables import is_local

if TYPE_CHECKING:
from collections.abc import Iterator
Expand Down
Loading
Loading