Skip to content

Commit 7248cb2

Browse files
committed
fix #2732 -- always show javascript eval error in jupyter
- also make the error more standard looking
1 parent dec6308 commit 7248cb2

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/packages/frontend/jupyter/output-messages/javascript-eval.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ maybe safer/cleaner than nothing.
1212
export function javascript_eval(line: string, element: any): string {
1313
let requirejs: any;
1414
let require: any;
15-
require = requirejs = () =>
16-
console.warn(
17-
// TODO: replace "CoCalc"?
15+
require = requirejs = () => {
16+
throw Error(
1817
"require is not available in CoCalc; if you need a Javascript library, please email [email protected].",
1918
);
19+
};
2020
let define = (..._) => {
2121
throw Error("Custom ipywidgets are not yet supported in CoCalc.");
2222
};
@@ -26,7 +26,7 @@ export function javascript_eval(line: string, element: any): string {
2626
try {
2727
eval(line);
2828
} catch (err) {
29-
console.warn(`Jupyter Eval Error: ${err} -- evaluating "${line}"`);
29+
console.warn(`Jupyter Javascript Error: ${err} -- evaluating "${line}"`);
3030
return `${err}`;
3131
}
3232
return "";

src/packages/frontend/jupyter/output-messages/javascript.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import $ from "jquery";
88
import React, { useRef, useState } from "react";
99
import { is_array } from "@cocalc/util/misc";
1010
import { javascript_eval } from "./javascript-eval";
11-
import { STDERR_STYLE } from "./style";
11+
import ShowError from "@cocalc/frontend/components/error";
1212

1313
interface JavascriptProps {
1414
value: string | List<string>;
1515
}
1616

1717
// ATTN: better don't memoize this, since JS code evaluation happens when this is mounted
1818
export const Javascript: React.FC<JavascriptProps> = (
19-
props: JavascriptProps
19+
props: JavascriptProps,
2020
) => {
2121
const { value } = props;
2222

@@ -52,16 +52,7 @@ export const Javascript: React.FC<JavascriptProps> = (
5252
}, [value]);
5353

5454
if (errors) {
55-
// This conflicts with official Jupyter
56-
return (
57-
<div style={STDERR_STYLE}>
58-
<span>
59-
{errors}
60-
<br />
61-
See your browser Javascript console for more details.
62-
</span>
63-
</div>
64-
);
55+
return <ShowError error={errors} style={{ margin: "10px 0" }} />;
6556
} else {
6657
return <div ref={node} />;
6758
}

0 commit comments

Comments
 (0)