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.

fix: have clearer tips when developing on marimo (#2783)

Myles Scolnick2602e2805434
diff --git a/frontend/vite.config.mts b/frontend/vite.config.mts
index 977378dd9c..4c817b0000 100644
--- a/frontend/vite.config.mts
+++ b/frontend/vite.config.mts
@@ -51,8 +51,54 @@ const htmlDevPlugin = (): Plugin => {
}
// fetch html from server
- const serverHtmlResponse = await fetch(TARGET + ctx.originalUrl);
- const serverHtml = await serverHtmlResponse.text();
+ let serverHtml: string;
+ try {
+ const serverHtmlResponse = await fetch(TARGET + ctx.originalUrl);
+ if (!serverHtmlResponse.ok) {
+ throw new Error("Failed to fetch");
+ }
+ serverHtml = await serverHtmlResponse.text();
+ } catch (e) {
+ console.error(
+ `Failed to connect to a marimo server at ${TARGET + ctx.originalUrl}`,
+ );
+ console.log(`
+A marimo server may not be running.
+Run \x1b[32mmarimo edit --no-token --headless\x1b[0m in another terminal to start the server.
+
+If the server is already running, make sure it is using port ${SERVER_PORT} with \x1b[1m--port=${SERVER_PORT}\x1b[0m.
+ `);
+ return `
+ <html>
+ <body style="padding: 2rem; font-family: system-ui, sans-serif; line-height: 1.5;">
+ <div style="max-width: 500px; margin: 0 auto;">
+ <h2 style="color: #e53e3e">Server Connection Error</h2>
+
+ <p>
+ Could not connect to marimo server at:<br/>
+ <code style="background: #f7f7f7; padding: 0.2rem 0.4rem; border-radius: 4px;">
+ ${TARGET + ctx.originalUrl}
+ </code>
+ </p>
+
+ <div style="background: #f7f7f7; padding: 1.5rem; border-radius: 8px;">
+ <div>To start the server, run:</div>
+ <code style="color: #32CD32; font-weight: 600;">
+ marimo edit --no-token --headless
+ </code>
+ </div>
+
+ <p>
+ If the server is already running, make sure it is using port
+ <code style="font-weight: 600;">${SERVER_PORT}</code>
+ with the flag
+ <code style="font-weight: 600;">--port=${SERVER_PORT}</code>
+ </p>
+ </div>
+ </body>
+ </html>
+ `;
+ }
const serverDoc = new JSDOM(serverHtml).window.document;
const devDoc = new JSDOM(html).window.document;
@@ -61,8 +107,20 @@ const htmlDevPlugin = (): Plugin => {
if (!serverHtml.includes("marimo-mode") && serverHtml.includes("login")) {
return `
<html>
- <body>
- In development mode, please run the server without authentication: <code style="color: red;">marimo edit --no-token</code>
+ <body style="padding: 2rem; font-family: system-ui, sans-serif; line-height: 1.5;">
+ <div style="max-width: 500px; margin: 0 auto;">
+ <h2 style="color: #e53e3e">Authentication Not Supported</h2>
+
+ <p>
+ In development mode, please run the server without authentication:
+ </p>
+
+ <div style="background: #f7f7f7; padding: 1.5rem; border-radius: 8px;">
+ <code style="color: #32CD32; font-weight: 600;">
+ marimo edit --no-token
+ </code>
+ </div>
+ </div>
</body>
</html>
`;