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
Add logging for WebSocket closure and errors, and conditionally enable debug logging in non-production environments (#22)
Myles Scolnick5f703ea64c8d
diff --git a/frontend/src/core/websocket/useMarimoWebSocket.tsx b/frontend/src/core/websocket/useMarimoWebSocket.tsxindex ea35f4a32f..74c45956bf 100644--- a/frontend/src/core/websocket/useMarimoWebSocket.tsx+++ b/frontend/src/core/websocket/useMarimoWebSocket.tsx@@ -13,6 +13,7 @@ import { sendInstantiate } from "../network/requests";import { CellId } from "../model/ids";import { CellState, createCell } from "../model/cells";import { useErrorBoundary } from "react-error-boundary";+import { Logger } from "@/utils/Logger";/*** WebSocket that connects to the Marimo kernel and handles incoming messages.@@ -139,6 +140,7 @@ export function useMarimoWebSocket(opts: {case "MARIMO_WRONG_KERNEL_ID":case "MARIMO_SHUTDOWN":+ Logger.warn("WebSocket closed", e.reason);setConnStatus({state: WebSocketState.CLOSED,code: WebSocketClosedReason.KERNEL_DISCONNECTED,@@ -171,12 +173,14 @@ export function useMarimoWebSocket(opts: {* When we encounter an error, we should close the connection.*/onError: (e) => {+ Logger.warn("WebSocket error", e);setConnStatus({state: WebSocketState.CLOSED,code: WebSocketClosedReason.KERNEL_DISCONNECTED,reason: "kernel not found",});- ws.current?.close();+ // Try reconnecting as this could have been a network error.+ ws.current?.reconnect();},});diff --git a/frontend/src/utils/Logger.ts b/frontend/src/utils/Logger.tsindex d5165d6574..85b66cad97 100644--- a/frontend/src/utils/Logger.ts+++ b/frontend/src/utils/Logger.ts@@ -11,7 +11,9 @@ interface ILogger {*/export const Logger: ILogger = {debug: (...args) => {- console.debug(...args);+ if (process.env.NODE_ENV !== "production") {+ console.debug(...args);+ }},log: (...args) => {console.log(...args);